Announcement Announcement Module
No announcement yet.
AnnotationContextAware and AutowireCapableBeanFactory Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #2
    1) No
    2) No

    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.