美文网首页
FactoryBean与Singleton

FactoryBean与Singleton

作者: 开往春天的扶手拖拉机 | 来源:发表于2017-08-29 23:06 被阅读0次

factoryBean是一个接口。isSingleton方法是说明getObject方法返回的是否是同一个对象。具体的实现是用户决定的,你可以在isSingleton返回true的同时,getObject每次都返回新的对象,当然这样只会坑到自己。
bean定义中的scope设置为Singleton时,说明这个bean是单例的,在AutoWired或者getBean时,获取的都是同一个bean。

isSingleton和scope不同组合条件下,bean的类型
isSingleton scope bean的类型
true singleton 单例
true prototype 非单例
false singleton 非单例
false prototype 非单例

相关文章

网友评论

      本文标题:FactoryBean与Singleton

      本文链接:https://www.haomeiwen.com/subject/jlaadxtx.html