lundi 2 mars 2015

Spring: ensure initialization order without 'depends-on'

I have kinda complex spring context and I want to ensure that beans will be initialized in specific order.



-+ module 1
++ root-context.xml
+- LocalSessionFactoryBean
-+ module 2
++ additional-context.xml
+- MyHijackingBean


Before module 1 was dependent on module 2. And LocalSessionFactoryBean was defined as:



<bean class="org.s.o.LocalSessionFactoryBean" depends-on="MyHijackingBean">


It was working great. MyHijackingBean was initialized with @PostConstruct before LocalSessionFactoryBean was created.


But now I have reversed dependency - module 2 is dependent on module 1. So module 1 doesn't know anything about MyHijackingBean


Can I somehow reverse depends-on? I've tried to use BeanPostProcessor, but there I don't have any possibility to control order of initalization.


Spring version - 3.2


Aucun commentaire:

Enregistrer un commentaire