Java – how to control the order of bean init method in spring?

Suppose I have a bean, then I should call the init method or constructor after the init method of another bean Is it possible?

Solution

Use the dependencies on attribute XML file in the spring context:

<bean id="beanOne" class="ExampleBean" depends-on="manager">
  <property name="manager"><ref local="manager"/></property>
</bean>

Or @ dependso if annotations are used, annotate on the bean

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>