Suppose I have bean, which init-method or constructor should be called after init-method of another bean. Is it possible?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use depends-on
attribute in spring context XML file:
<bean id="beanOne" class="ExampleBean" depends-on="manager">
<property name="manager"><ref local="manager"/></property>
</bean>
or @DependsOn
annotation on bean if you are using annotations.
回答2:
Use @DependsOn
annotation or depends-on attribute if you're using xml configuration.
回答3:
You can use de depends-on
attribute on your second bean.
Reference: http://static.springsource.org/spring/docs/1.2.x/reference/beans.html#beans-factory-dependson