Browse Source

Polishing

pull/24616/head
Juergen Hoeller 7 years ago
parent
commit
b6b880ce27
  1. 3
      spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
  2. 2
      spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
  3. 4
      spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java
  4. 26
      spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java

3
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

@ -403,8 +403,7 @@ public abstract class BeanUtils {
/** /**
* Retrieve the JavaBeans {@code PropertyDescriptor}s of a given * Retrieve the JavaBeans {@code PropertyDescriptor}s of a given class.
* class.
* @param clazz the Class to retrieve the PropertyDescriptors for * @param clazz the Class to retrieve the PropertyDescriptors for
* @return an array of {@code PropertyDescriptors} for the given class * @return an array of {@code PropertyDescriptors} for the given class
* @throws BeansException if PropertyDescriptor look fails * @throws BeansException if PropertyDescriptor look fails

2
spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java

@ -115,7 +115,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
this.destroyMethod = determineDestroyMethod(destroyMethodName); this.destroyMethod = determineDestroyMethod(destroyMethodName);
if (this.destroyMethod == null) { if (this.destroyMethod == null) {
if (beanDefinition.isEnforceDestroyMethod()) { if (beanDefinition.isEnforceDestroyMethod()) {
throw new BeanDefinitionValidationException("Couldn't find a destroy method named '" + throw new BeanDefinitionValidationException("Could not find a destroy method named '" +
destroyMethodName + "' on bean with name '" + beanName + "'"); destroyMethodName + "' on bean with name '" + beanName + "'");
} }
} }

4
spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java

@ -381,8 +381,8 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
* @param beanName the name of the bean (may be {@code null}) * @param beanName the name of the bean (may be {@code null})
* @param beanClass the class of the bean (resolving a public constructor * @param beanClass the class of the bean (resolving a public constructor
* to be autowired, possibly simply the default constructor) * to be autowired, possibly simply the default constructor)
* @param customizers one or more callbacks for customizing the * @param customizers one or more callbacks for customizing the factory's
* factory's {@link BeanDefinition}, e.g. setting a lazy-init or primary flag * {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
* @since 5.0 * @since 5.0
* @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...) * @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...)
*/ */

26
spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java

@ -105,6 +105,24 @@ public class AnnotationConfigApplicationContextTests {
} }
} }
@Test
public void getBeanByTypeAmbiguityRaisesException() {
ApplicationContext context = new AnnotationConfigApplicationContext(TwoTestBeanConfig.class);
try {
context.getBean(TestBean.class);
}
catch (NoSuchBeanDefinitionException ex) {
assertThat(ex.getMessage(),
allOf(
containsString("No qualifying bean of type '" + TestBean.class.getName() + "'"),
containsString("tb1"),
containsString("tb2")
)
);
}
}
/** /**
* Tests that Configuration classes are registered according to convention * Tests that Configuration classes are registered according to convention
* @see org.springframework.beans.factory.support.DefaultBeanNameGenerator#generateBeanName * @see org.springframework.beans.factory.support.DefaultBeanNameGenerator#generateBeanName
@ -370,14 +388,6 @@ public class AnnotationConfigApplicationContextTests {
} }
} }
static class ConfigMissingAnnotation {
@Bean
public TestBean testBean() {
return new TestBean();
}
}
@Configuration @Configuration
static class TwoTestBeanConfig { static class TwoTestBeanConfig {

Loading…
Cancel
Save