Shikarn-O
Shikarn-O

Reputation: 3417

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

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

Upvotes: 9

Views: 14042

Answers (3)

soulcheck
soulcheck

Reputation: 36767

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

Upvotes: 5

Tomas Narros
Tomas Narros

Reputation: 13468

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

Upvotes: 4

AlexR
AlexR

Reputation: 115328

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.

Upvotes: 14

Related Questions