@ -409,23 +409,36 @@ class ConfigurationClassPostProcessorTests {
beanFactory . registerBeanDefinition ( "config" , new RootBeanDefinition ( SingletonBeanConfig . class ) ) ;
beanFactory . registerBeanDefinition ( "config" , new RootBeanDefinition ( SingletonBeanConfig . class ) ) ;
beanFactory . setAllowBeanDefinitionOverriding ( false ) ;
beanFactory . setAllowBeanDefinitionOverriding ( false ) ;
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor ( ) ;
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor ( ) ;
assertThatExceptionOfType ( BeanDefinitionStoreException . class )
assertThatIllegalStateException ( )
. isThrownBy ( ( ) - > pp . postProcessBeanFactory ( beanFactory ) )
. isThrownBy ( ( ) - > pp . postProcessBeanFactory ( beanFactory ) )
. withMessageContaining ( "bar" )
. withMessage ( "Failed to load bean definitions for configuration class '%s'" , SingletonBeanConfig . class . getName ( ) )
. withMessageContaining ( "SingletonBeanConfig" )
. havingCause ( )
. withMessageContaining ( TestBean . class . getName ( ) ) ;
. isInstanceOf ( BeanDefinitionStoreException . class )
. withMessageContainingAll (
"bar" ,
"SingletonBeanConfig" ,
TestBean . class . getName ( )
) ;
}
}
@Test // gh-25430
@Test // gh-25430
void detectAliasOverride ( ) {
void detectAliasOverride ( ) {
Class < ? > configClass = SecondConfiguration . class ;
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ( ) ;
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ( ) ;
DefaultListableBeanFactory beanFactory = context . getDefaultListableBeanFactory ( ) ;
DefaultListableBeanFactory beanFactory = context . getDefaultListableBeanFactory ( ) ;
beanFactory . setAllowBeanDefinitionOverriding ( false ) ;
beanFactory . setAllowBeanDefinitionOverriding ( false ) ;
context . register ( FirstConfiguration . class , SecondConfiguration . class ) ;
context . register ( FirstConfiguration . class , configClass ) ;
assertThatIllegalStateException ( ) . isThrownBy ( context : : refresh )
assertThatIllegalStateException ( ) . isThrownBy ( context : : refresh )
. withMessageContaining ( "alias 'taskExecutor'" )
. withMessage ( "Failed to load bean definitions for configuration class '%s'" , configClass . getName ( ) )
. withMessageContaining ( "name 'applicationTaskExecutor'" )
. havingCause ( )
. withMessageContaining ( "bean definition 'taskExecutor'" ) ;
. isExactlyInstanceOf ( IllegalStateException . class )
. withMessageContainingAll (
"alias 'taskExecutor'" ,
"name 'applicationTaskExecutor'" ,
"bean definition 'taskExecutor'"
) ;
context . close ( ) ;
context . close ( ) ;
}
}
@ -1158,8 +1171,11 @@ class ConfigurationClassPostProcessorTests {
@Test
@Test
void testNameClashBetweenConfigurationClassAndBean ( ) {
void testNameClashBetweenConfigurationClassAndBean ( ) {
assertThatExceptionOfType ( BeanDefinitionStoreException . class )
assertThatIllegalStateException ( )
. isThrownBy ( ( ) - > new AnnotationConfigApplicationContext ( MyTestBean . class ) . getBean ( "myTestBean" , TestBean . class ) ) ;
. isThrownBy ( ( ) - > new AnnotationConfigApplicationContext ( MyTestBean . class ) )
. withMessage ( "Failed to load bean definitions for configuration class '%s'" , MyTestBean . class . getName ( ) )
. havingCause ( )
. isInstanceOf ( BeanDefinitionStoreException . class ) ;
}
}
@Test
@Test