Dec 8th, 2010, 12:09 PM
AnnotationContextAware and AutowireCapableBeanFactory
I've got a couple of classes implementing ApplicationContextAware. I create my objects by myself and pass them to the autowireBean- Method in an AutowireCapableBeanFactory. Doing so, the setApplicationContext()- Method is never called. It is possible to get an application context by creating a field of type ApplicationContext and annotate it with @autowired.
I guess that's because autowireBean() performs autowiring only and an Interface is no autowiring.
(1) Is my guess correct?
(2) Is there any chance to make spring call setApplicationContext() on an object not created by the container?
Dec 9th, 2010, 02:02 AM
The ApplicationContextAware is a marker interface which is called after bean construction by a BeanPostProcessor, as you are instantiating beans yourself the initialization and BeanPostProcessors aren't called for your beans.