bean的singleton(没有看到生命周期范围??)
4.5.1 The singleton scope
Only one shared instance of a singleton bean is managed, and all requests for beans with an id or ids matching that bean definition result in that one specific bean instance being returned by the Spring container.
To put it another way, when you define a bean definition and it is scoped as a singleton, the Spring IoC container creates exactly one instance of the object defined by that bean definition. This single instance is stored in a cache of such singleton beans(这种实例存储在这种单例beans的缓存中), and all subsequent requests and references for that named bean return the cached object.(所有后续的请求和对bean对象的引用都返回缓存的对象) 单例模式的特点
Figure 4.2.

Spring’s concept of a singleton bean differs from the Singleton pattern as defined in the Gang of Four (GoF) patterns book. The GoF Singleton hard-codes the scope of an object such that one and only one instance of a particular class is created per ClassLoader. The scope of the Spring singleton is best described as per container and per bean. This means that if you define one bean for a particular class in a single Spring container, then the Spring container creates one and only one instance of the class defined by that bean definition. The singleton scope is the default scope in Spring. To define a bean as a singleton in XML, you would write, for example:
<bean id="accountService" class="com.foo.DefaultAccountService"/> <!-- the following is equivalent, though redundant (singleton scope is the default) -->
<bean id="accountService" class="com.foo.DefaultAccountService" scope="singleton"/>
bean的singleton(没有看到生命周期范围??)的更多相关文章
- 手把手教你写DI_3_小白徒手支持 `Singleton` 和 `Scoped` 生命周期
手把手教你写DI_3_小白徒手支持 Singleton 和 Scoped 生命周期 在上一节:手把手教你写DI_2_小白徒手撸构造函数注入 浑身绷带的小白同学:我们继续开展我们的工作,大家都知道 Si ...
- bean的autowire属性及其生命周期
一:sutowire属性 1.no:默认值,禁用自动装配: 2.byName:根据属性名称自动装配: 3.byType:根据属性类型自动装配: 4.constructor:通过构造方法自动装配,不推荐 ...
- bean在容器上的生命周期
初始化两种方法: 1,使用init-method属性指定那个方法在bean依赖关系设置好后自动执行. 2,实现initializingBean接口 实现 ...
- Spring之BeanFactory及Bean生命周期
1.spring通过BeanFactory灵活配置.管理bean,Spring对管理的bean没有任何特别的要求,完全支持对POJO的管理: 2.BeanFactory有个ApplicationCon ...
- Bean生命周期及BeanFactory
1.spring通过BeanFactory灵活配置.管理bean,Spring对管理的bean没有任何特别的要求,完全支持对POJO的管理: 2.BeanFactory有个ApplicationCon ...
- 从启动日志看Spring IOC的初始化和Bean生命周期
一.Tomcat中启动IoC容器的日志 启动Tomcat等容器时,控制台每次都打印出一些日志. 最近刚好在研究Spring源码,所以换个角度,从启动日志来简单的看看Spring的初始化过程! 以下是T ...
- Bean的生命周期
Bean的生命周期 原文:http://997004049-qq-com.iteye.com/blog/1729793 任何一个事物都有自己的生命周期,生命的开始.生命中.生命结束.大家最熟悉的应该是 ...
- Spring 了解Bean的一生(生命周期)
转载 https://blog.csdn.net/w_linux/article/details/80086950 该篇博客就来了解IoC容器下Bean的一生吧,也可以理解为bean的生命周期. ## ...
- 4.spriing:Bean的生命周期/工厂方法配置Bean/FactoryBean
1.Bean的生命周期 scope:singleton/prototype 1)spring容器管理singleton作用的生命周期,spring能够精确知道Bean合适创建,何时初始化完成,以及何时 ...
- Spring 框架基础(02):Bean的生命周期,作用域,装配总结
本文源码:GitHub·点这里 || GitEE·点这里 一.装配方式 Bean的概念:Spring框架管理的应用程序中,由Spring容器负责创建,装配,设置属性,进而管理整个生命周期的对象,称为B ...
随机推荐
- .Net平台下实例类型无法转换成接口类型?
首先这种情况出现在应用程序启动前的方法里面. 本想通过发射来实现一些功能.谁知道被这个坑了. 碰到这种问题.已经相当无语了.同时也不知道该如何解决.望有能之士帮忙解答 using System; us ...
- gcd的性质+分块 Bzoj 4028
4028: [HEOI2015]公约数数列 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 865 Solved: 311[Submit][Statu ...
- HDU 1573 CRT
CRT模板题 /** @Date : 2017-09-15 13:52:21 * @FileName: HDU 1573 CRT EXGCD.cpp * @Platform: Windows * @A ...
- [php]几个常用函数
count(arr);用于统计数组的元素个数 is_array(arr);判断给定变量是不是数组 var_dump(var||arr);打印数组或变量信息(类型和值): print_r(var||ar ...
- Try finally的一个实验和为什么避免重载 finalize()方法--例子
public class TryFinallTest { public TryFinallTest(){ } public void runSomething(String str){ System. ...
- MongoDB中的基础概念:Databases、Collections、Documents
MongoDB以BSON格式的文档(Documents)形式存储.Databases中包含集合(Collections),集合(Collections)中存储文档(Documents). BSON是一 ...
- 【洛谷 P2472】 [SCOI2007]蜥蜴 (最大流)
题目链接 简单网络流. 源点向蜥蜴连流量为\(1\)的边. 能跳出去的点向汇点连流量为\(INF\)的边. 把每个点拆成\(2\)个点,\(O(n^4)\)枚举两两点,如果距离小于等于\(d\),就互 ...
- 简谈CSS 中的 em,rem,px,%
在实际工作中,可能我们用的比较多的是‘%’ 和 px,但是我们也经常看到很多网站和css框架里用的是em 或rem.而‘%’ 和px已经都是比较常见或者说是常用.但是em 和rem 却鲜有使用,一直以 ...
- 商城项目(ssm+dubbo+nginx+mysql统合项目)总结(4)
我不会在这里贴代码和详细步骤什么的,我觉得就算我把它贴出来,你们照着步骤做还是会出很多问题,我推荐你们去看一下黑马的这个视频,我个人感觉很不错,一步一步走下来可以学到很多东西.另外,视频和相关文档的话 ...
- 64_p2
perl-Class-XSAccessor-1.19-10.fc26.x86_64.rpm 12-Feb-2017 15:12 48098 perl-Clipboard-0.13-16.fc26.no ...