https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/annotation/Autowired.html I read the doc about @autowired ,found that the doc saying "Not supported in BeanPostProcessor or BeanFactoryPostProcessor". But i found that @Autowired can not working in BeanFactoryPostProcessor ,but it can working in BeanPostProcessor .
Comment From: nikasakandelidze
Hello, any updates regarding this issue?
Comment From: maoqingcode
Hello, any updates regarding this issue?
@Component
public class SimpleService implements BeanPostProcessor{
@Autowired
private SimpleBean simpleBean;
public void query(){
System.out.println(simpleBean);
}
}
the @autowired can work, you can get a instance. if you use BeanFactoryPostProcessor ,@autowired not working.
Comment From: snicoll
the @Autowired can work, you can get a instance.
It's a vast simplification of the prolem. A BeanPostProcessor
is supposed to be created (and usable) before any beans than it is supposed to post-process. The example you've shared means that SimpleBean
won't be post-processed. This may be ok for you but stating that autowiring works for BPP is not a good idea.
In general such low-level beans should be declared with a static
@Bean
method and only require other infrastructure beans (such as the environment or the bean factory).