spring Bean的作用域(注解 单例 多例)

通过@Scope注解,指定Bean的作用域(默认是 singleton 单例)

回顾:XML的方式<bean id=”” class=”” scope=”prototype”>

 

//测试生命周期过程中的初始化和销毁bean

@Component("lifeCycleBean")

//@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE)

@Scope("prototype")//默认是单例(singleton),更改为多例(prototype)

public class LifeCycleBean {

 

}

猜你喜欢

转载自blog.csdn.net/qq_15204179/article/details/82975115