我们正在从Spring 3.2.4升级到Spring 4.3.8,其中singleton =" false"不再受支持。什么是设置单身'假'在Spring 4.3.8? 如果singeton =" false"那么这是否意味着spring bean范围已成为" Prototype"?
答案 0 :(得分:2)
您可以使用@Scope指定原型bean。
例如:
@Bean @Scope("prototype")
public Person personPrototype() {
return new Person();
}
进一步阅读link
答案 1 :(得分:0)
据我记忆,singleton=false
是出于某些兼容性原因而保留的,在一些较旧的docs, eg 3.0.0.M3中也有说明:
<bean id="accountService" class="com.foo.DefaultAccountService"/>
以下是等效的,尽管是冗余的(单例范围是默认值);使用spring-beans-2.0.dtd
<bean id="accountService"> class="com.foo.DefaultAccountService" scope="singleton"/>
以下内容是等效的,并保留为spring-beans.dtd 中的向后兼容性
<bean id="accountService"> class="com.foo.DefaultAccountService" singleton="true"/>
无论如何,默认的弹簧范围是singleton
,所以即使未指定,但是can be changed to prototype
(or whatever you need) with:
scope="prototype"
@Scope("prototype")
或@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
答案 2 :(得分:0)
正确的,scope =“ prototype”与singleton =“ false”的直接等效。