I am using Spring 3.0.2. I have two relatively simple definitions of bean. One has @PostConstruct (bean 'A'), which fires up an event chain for which you need to prepare @DependsOn bean (bean 'B'). However, it seems, although I stated that the bean 'A' depends on the bean 'B', the events (lifecycle methods) of the bean 'A' work until the bean 'B' is fully initialized.
Does a bean say "depends" on @DependsOn (or, if it depends, depends on the definition of a bean), does it mean that dependent w810 lifecycle methods will complete before a bean that depends on the bean mentioned?
Will the bean 'B' life cycle methods be executed before the bean 'A'?
UPDATE
Bean A is a custom class that uses the JMS template to send a message about its initialization.
The receiver of this message processes it and redirects it to MessageListeningContainer (bean B).
The first part is executed before the bean B was launched by the DefaultLifecycleProcessor.
@Component @DependsOn("beanB") public class BeanA { @PostConstruct public void init() { // do stuff } } <bean id="beanB" class="org.springframework.jms.listener.DefaultMessageListenerContainr"> </bean>
I added bean b injection to my init method, plus two registration statements:
container.isRunning(); container.isActive();
I looked at the Spring source, and isActive is true after the Initialization method (doInitialized is complete). IsRunning is set after doStart completes. DoStart is launched using the DefaultLifecycleProcessor, which occurs after calling the annotated @PostConstruct methods.
How can I guarantee that my Postconstruct method is called AFTER the bean b is initialized and started?
predhme
source share