-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Doc: @Autowired not working in BeanFactoryPostProcessor [SPR-4935] #9610
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
Rafał Piotrowski commented Example of bug. You have to run SampleServiceTest (as JUnit4 test). |
Rafał Piotrowski commented AbstractApplicationContext.java: [...] As you can see BeanFactoryPostProcessors are created and invoked before any BeanPostProcessor is created. AutowiredAnnotationBeanPostProcessor (postprocessor responsible for |
Juergen Hoeller commented This is actually intended: Annotation-based injection is available to application objects only, which in particular excludes post-processors. The technical reason for this is that annotation processing itself is implemented as post-processors. That said - it's also by definition, so we need to document this properly. Juergen |
Rafał Piotrowski commented The same thing applies to factoryBeans and to beans that factoryBeans use (that are inject to some factoryBean by XML) when beanFactoryPostprocessor invokes beanFactory.getBeansOfType(Class) or beanFactory.getBeansOfType(Class, boolean, boolean) with last argument set to true. Attached zip contains updated sample application with JUnit4 test class (SampleTest). |
Paul Benedict commented Juergen, that documentation should go straight into the annotation's javadoc. That limitation sounds too important to be left to the Reference guide alone. |
Dave Syer commented Rafal: the factory bean effect you are seeing is a side effect of the implementation of your BeanFactoryPostProcessor - if you play with the bean instances from the BeanFactory in a factory post processor, you bypass the normal ApplicationContext bean creation features, like applying BeanPostProcessors. In other words: it's expected behaviour. I'll change this issue to a documentation issue. |
Oliver Drotbohm commented Attached patch to alter |
Oliver Drotbohm commented Forward to Jürgen to review and apply patch. |
Chris Beams commented Thanks, Ollie for the patch. With minor modifications it has been applied, as well as a similar update to |
Rafał Piotrowski opened SPR-4935 and commented
I create simple bean which implements BeanFactoryPostProcessor and has dependent bean injected with
@Autowired
annotation. Injection does not occur.Workaround is to use standard XML dependency injection.
Affects: 2.5.4
Attachments:
Issue Links:
@Value
("is duplicated by")Referenced from: commits a557878
0 votes, 6 watchers
The text was updated successfully, but these errors were encountered: