如何在Spring中控制bean init-method调用的顺序? [英] How to control order of bean init-method invocation in Spring?

查看:227
本文介绍了如何在Spring中控制bean init-method调用的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有bean,应该在另一个bean的init-method之后调用init-method或constructor。可能吗?

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

推荐答案

在spring上下文XML文件中使用 depends-on 属性:

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>

@DependsOn 如果你在bean上注释正在使用注释。

or @DependsOn annotation on bean if you are using annotations.

这篇关于如何在Spring中控制bean init-method调用的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆