8.2.5 Spring 3.0 新增的注解
@DependsOn @Lazy
@DependsOn :用于强制初始化其他Bean。修饰Bean类或方法,可以指定一个字符串数组作为参数,每个数组元素对应一个强制初始化的Bean。
package edu.pri.lime._8_2_5.bean; import org.springframework.context.annotation.DependsOn; import org.springframework.stereotype.Component; @DependsOn({"steelAxe","lime"}) //指定在初始化chinese Bean之前,会强制初始化steelAxe、lime两个Bean @Component public class Chinese { }
@Lazy : 用于指定该Bean是否取消预初始化。
package edu.pri.lime._8_2_5.bean; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @Lazy(true) //修饰Spring Bean 类用于指定该Ben的预初始化行为,指定一个boolean型的value属性,该属性决定是否要预初始化该Bean @Component public class French { }
啦啦啦
Spring3.0新注解
本文介绍Spring3.0中引入的两个新注解@DependsOn和@Lazy。@DependsOn用于确保某些Bean在其他Bean之前被初始化;而@Lazy则允许开发者控制Bean的懒加载行为。
256

被折叠的 条评论
为什么被折叠?



