为了账号安全,请及时绑定邮箱和手机立即绑定

java spring4.0如何设置 singleton?

java spring4.0如何设置 singleton?

斯蒂芬大帝 2019-02-13 17:17:50
java spring4.0如何设置 singleton? 
查看完整描述

1 回答

?
胡说叔叔

TA贡献1804条经验 获得超8个赞

Spring中管理的所有Bean默认都是singleton的
<bean id="command" class="fiona.apple.AsyncCommand" />

如果想将Bean配置成非单例的,可以通过配置scope来说明
<!-- a stateful bean deployed as a prototype (non-singleton) -->
<bean id="command" class="fiona.apple.AsyncCommand" scope="prototype"/>
这样每次获取AsyncCommand对象是都会创建一个新的对象

查看完整回答
反对 回复 2019-02-16
  • 1 回答
  • 0 关注
  • 1294 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信