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 | 非单例 |










网友评论