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

java spring4.0如何设置 singleton?

java spring4.0如何设置 singleton?

ibeautiful 2019-02-20 18:13:28
java spring4.0如何设置 singleton? 
查看完整描述

1 回答

?
qq_笑_17

TA贡献1818条经验 获得超7个赞

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-03-02
  • 1 回答
  • 0 关注
  • 530 浏览
慕课专栏
更多

添加回答

举报

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