1.15bean标签中的depends-on
戴着假发的程序员出品
[查看视频教程]
depends-on属性主要配置当前bean的依赖。当然大部分情况下我们都是使用ref标签完成属性依赖。
但是ref是属性的注入。depends-on仅仅是表示依赖,不一定会注入。
depends-on表现情况就是:如果A 的depends-on配置的是B,则spring会在创建A之前先创建B,会在销毁B之前先下回A。
我们添加一个OtherUtile类。
1 /** 2 * @author 戴着假发的程序员 3 * 4 * @description 5 */ 6 public class OtherUtil { 7 public OtherUtil(){ 8 System.out.println("实例化:OtherUtil"); 9 } 10 }
配置如下:
1 <!-- 注册accountService --> 2 <bean id="accountService" 3 depends-on="otherUtile" 4 autowire="byType" class="com.dk.demo1.service.AccountService"/> 5 <!-- 注册otherUtil --> 6 <bean id="otherUtile" class="com.dk.demo1.util.OtherUtil"/>
当depends-on中可以配置多个bean,使用“,”隔开
测试:

我是戴着假发的程序员,分享技术,分享经验,如果要转载,请注明:出自戴着假发的程序员

浙公网安备 33010602011771号