Announcement Announcement Module
No announcement yet.
BeanPostProcessors should be instantiated first Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanPostProcessors should be instantiated first

    I have an interface in my application similar to "BeanFactoryAware". I've created a BeanPostProcessor In order to automatically inject beans that implement my custom interface. I would like to simply define the BeanPostProcessor bean in my app context to have Spring automatically utilize it when instantiating other beans. However, this is not working. Upon startup the app context will begin to instantiate all singletons, however it will not instantiate my BeanPostProcessor first, and so any beans instantiated before the BeanPostProcessor do not get the benefit of the BeanPostProcessor. Shouldn't Spring determine which contained beans implement the BeanPostProcessor interface and give them a higher instantiation priority? I could have my other beans "depend-on" my BeanPostProcessor, but then that kind of defeats the purpose of the BeanPostProcessor (it creates an explicit relationship in my Spring config when I was trying to make it implicit and automatic). I realize that I could manually instantiate the BeanPostProcessor and set it up before loading the config file, but this is something I want to avoid.

    - Andy

  • #2
    To answer my own question - BeanPostProcessors are instantiated first. My problem was that one BeanPostProcessor (through a series of dependencies) ended up referencing a bean that depended on another BeanPostProcessor before its afterPropertiesSet() was called.