How to control order of bean init-method invocation in Spring?

后端 未结 3 1238
夕颜
夕颜 2021-01-12 01:40

Suppose I have bean, which init-method or constructor should be called after init-method of another bean. Is it possible?

相关标签:
3条回答
  • 2021-01-12 02:15

    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.

    0 讨论(0)
  • 2021-01-12 02:29

    Use @DependsOn annotation or depends-on attribute if you're using xml configuration.

    0 讨论(0)
  • 2021-01-12 02:33

    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

    0 讨论(0)
提交回复
热议问题