spring 注解开发开发
懒加载
@Lazy
只针对Scope 为 singleton 的时候, 当IOC创建时不加载类,直到第一次使用的时候在加载到IOC中,并且初始化
用法
@Lazy
@Bean
public Person getPerson() {
return new Person("w", 22);
}
源码解析
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Lazy {
/**
* Whether lazy initialization should occur.
*/
boolean value() default true;
}
近期评论