zoukankan      html  css  js  c++  java
  • 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. 

    singleton

    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"/>
  • 相关阅读:
    【Linux 编程】进程间通信
    毕设进行时——4.3寸在富士通ARM中实现
    spcomm使用:在编译运行时为什么总出现"unable to open include file 'spcomm.hpp'"?
    Xilinx LVDS
    Xilinx selectIO
    xilinx 原理图输入
    http消息头(转)
    用java语言将数据库中的数据表转换为xml文件的通用程序(转)
    数据字典实例
    Web Service工作原理初探
  • 原文地址:https://www.cnblogs.com/batman425/p/7476504.html
Copyright © 2011-2022 走看看