Aaron, I believe that your code is correct but I used the following:
B bean = new B();
AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
factory.autowireBean( bean );
factory.initializeBean( bean, "bean" );
The first method will process @Autowire
fields and methods (but not classic properties). The second method will invoke post processing (@PostConstruct
and any defined BeanPostProcessor
s).
Application context can be obtained in a bean if it implements ApplicationContextAware
interface.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…