Description
Osvaldas Grigas opened SPR-8269 and commented
When using AnnotationConfigApplicationContext, if I declare at least one @Bean
of type BeanFactoryPostProcessor (even if it's a stub that doesn't do anything), this breaks default post-processing of the @Configuration
bean, meaning that @Autowired
fields are no longer injected, @PostConstruct
methods are not called, etc.
I'm attaching a test case to prove my point.
A workaround is to manually add the relevant BeanPostProcessors (like AutowiredAnnotationBeanPostProcessor and CommonAnnotationBeanPostProcessor) to BeanFactory.
Same thing happens in web app when I use ContextLoaderInitializer to load @Configuration
classes or define them through XML config. My particular case is that I use MyBatis-Spring integration and I cannot declare a @Bean
of type org.mybatis.spring.mapper.MapperScannerConfigurer using annotation config, because this bean is a BeanFactoryPostProcessor and thus breaks autowiring of @Configuration
class.
Affects: 3.1 M1
Attachments:
- org.mybatis.spring.sample.zip (8.37 kB)
- testcase.zip (1.98 kB)
Issue Links:
- @PostConstruct and PropertyPlaceholderConfigurer do not work together in AnnotationConfigApplicationContext [SPR-8257] #12905
@PostConstruct
and PropertyPlaceholderConfigurer do not work together in AnnotationConfigApplicationContext ("is duplicated by") - BeanDefinitionRegistryPostProcessor registered via @Bean will not be invoked [SPR-7868] #12525 BeanDefinitionRegistryPostProcessor registered via
@Bean
will not be invoked - Method postProcessBeanDefinitionRegistry is not called if the bean implements BeanDefinitionRegistryPostProcessor [SPR-9464] #14099 Method postProcessBeanDefinitionRegistry is not called if the bean implements BeanDefinitionRegistryPostProcessor
- Warn about non-static BeanDefinitionRegistryPostProcessor declarations on @Configuration classes [SPR-14234] #18808 Warn about non-static BeanDefinitionRegistryPostProcessor declarations on
@Configuration
classes
Referenced from: commits 52bef0b