Spring注解说明

 @scope("singleton")

#什么都不传是singleto是单实例,容器启动的时候创建对象,放到IOC中,用到的时候到IOC中获取,

#如果传prototype表示是多实例,容器启动的时候不创建对象,在调用的时候创建容器到IOC中。且调用一次创建一次。

@bean

public Student student(){

return new Student();

}
2.懒加载

@lazy

容器启动不创建对象,调用的时候创建对象

@lazy

@bean

public Student student(){

return new Studnet();

}

@Conditional({WindowConditional.class})
WindowConditional 实现condition接口,返回true

如果注解标记在类上,纳米是true类中的对象才会加入到容器中,如果标记在方法上,方法中的对象才会放到容器中。

猜你喜欢

转载自www.cnblogs.com/sz-jack/p/9286711.html