架构师之spring-----spring3.0新特性的bean加载控制@DependsOn和@Lazy

1.前言。
   如题。
2.描述。
  

@DependsOn用于强制初始化其他Bean。可以修饰Bean类或方法,使用该Annotation时可以指定一个字符串数组作为参数,每个数组元素对应于一个强制初始化的Bean。

@DependsOn({"steelAxe","abc"})
@Component
public class Chinese implements Person{
   //codes here
}
@Lazy用于指定该Bean是否取消预初始化。主要用于修饰Spring Bean类,用于指定该Bean的预初始化行为,使用该Annotation时可以指定一个boolean型的value属性,该属性决定是否要预初始化该Bean。

@Lazy(true)
@Component
public class Chinese implements Person{
   //codes here
}



转自:http://www.xuebuyuan.com/965172.html

猜你喜欢

转载自nannan408.iteye.com/blog/2226254