-
Notifications
You must be signed in to change notification settings - Fork 38.5k
BeanFactoryPostProcessor breaks default post-processing of @Configuration classes [SPR-8269] #12917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Osvaldas Grigas commented Of course, by "ContextLoaderInitializer" I meant ContextLoaderListener, but you got the point. |
Chris Beams commented Thanks for the report, Osvaldas. This has indeed been an issue known about, at least internally, for some time. There is a fundamental lifecycle conflict in handling BeanFactoryPostProcessor To resolve this issue, it is now possible to declare
|
Chris Beams commented Osvaldas - as an additional note, it looks like MapperScannerConfigurer should really be a BeanDefinitionRegistryPostProcessor instead of a BeanFactoryPostProcessor. The reason for this is that it actually registers additional beans (through scanning) as opposed to simply post-processing additional bean definitions. I realize you're not responsible for this class, but you might want to relay it to the Mybatis team. At a glance, I'm not sure how nicely this class will play with the I'd be happy to talk with the Mybatis team if they wish to discuss. Note that BeanDefinitionRegistryPostProcessor is a specialization of BeanFactoryPostProcessor, so they sholud be able to refactor in a backward-compatible way. |
Osvaldas Grigas commented Thanks for the fix! If you think that it's now possible to register BDRPP using |
Putthibong Boonbong commented MapperScannerConfigurer was changed to be BeanDefinitionRegistryPostProcessor in version 1.0.2 but it throw error when work with PropertyPlaceholderConfigurer. Please check my attachment. |
Chris Beams commented
No, it is still not possible to register a BDRPP from within a
Thanks for attaching the reproduction project. I ran the tests, and it fails as follows:
That last bit:
is happening because The reason for this is that BDRPP implementations are always processed by the container before As a rule, To work around this issue, if you are using Spring 3.1 you can consider injecting the |
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:
Issue Links:
@PostConstruct
and PropertyPlaceholderConfigurer do not work together in AnnotationConfigApplicationContext ("is duplicated by")@Bean
will not be invoked@Configuration
classesReferenced from: commits 52bef0b
The text was updated successfully, but these errors were encountered: