Spring finishing 7 - Bean scope


    <bean scope="singleton"/>


    <bean scope="prototype"/>

spring Bean's scope: The main property of the label by the <bean> scope decisions.

scope to value:

* Singleton: each call to getBean return the same instance of time

* Prototype: each call to getBean different instances when the return

Example code:


public class Bean {



Test code:

public class ScopeTest extends TestCase {

    private BeanFactory factory;


    protected void setUp() throws Exception {

       factory = new 



    public void testScope1() {

       Bean1 bean11 = (Bean1)factory.getBean("bean1");

       Bean1 bean12 = (Bean1)factory.getBean("bean1");

       if (bean11 == bean12) {


       }else {




分类:Java 时间:2010-05-12 人气:181
blog comments powered by Disqus


  • spring --- Bean scope of the description (Singleton and prototype) 2010-04-28

    Bean's scope description (Singleton and prototype) Spring Bean scope description: (1) singleton: SpringIoc container will only create an instance of the Bean, all the requests and only use this instance of the reference (2) Property: Each request is

  • Prototype. Scope. Full explanation of the closure (b) 2010-11-25

    So far, these are done automatically, and by the construction and implementation of the source (the mechanism) control. The scope chain execution environment defines the function object created by [[scope]] property, while the object function [[scope

  • Prototype. Scope. Full explanation of the closure (a) 2010-11-25

    Original : Richard Cornford. March 2004. Translation: the poor desert autumn 2010-11-23 Script Doll team produced Introduction Closure Closure is an expression (usually a function), can have any parameters, together with the binding of these paramete

  • (Transfer) JAVA programming and how to optimize code to improve performance JAVA 2010-07-20

    By using a number of complementary tools to find process bottlenecks, and bottlenecks on the part of the code can be optimized. There are two options: to optimize the code or change the design. We usually choose the latter, because the do not call th

  • Spring singleton bean 与 prototype bean 的依赖 2015-05-07

    本文同步至:http://www.waylau.com/spring-singleton-beans-with-prototype-bean-dependencies/ 问题 我们知道,Spring bean 默认的 scope 是 singleton(单例),但有些场景(比如多线程)需要每次调用都生成一个实例, 此时 scope 就应该设为 prototype.如: * @see java.lang.Runnable#run() @Scope("prototype") public

  • Pager-taglib.jar (page components) 2010-03-30

    The solution is to follow the MVC pattern to do, based on STRUTS framework. Divided into three parts, the presentation layer using a JSP, including JSTL and pager taglib used to do paging; control layer is to use very traditional Action; underlying t

  • With a code to describe the JAVA language support for principles of international 2010-09-21

    Get with the relevant international country code and the language version of the code: package com.hanmiao.internationalization; import java.util.Locale; public class LocaleExample { public static void main(String[] args) { Locale[] locales = Locale.

  • [Transfer] C / C + + language to explore the deep void and void pointer 2010-10-22

    1. Overview many beginners on the C / C + + language in the void and the void pointer type do not understand, so in the use of some errors. This paper will be void explain the profound meaning of keywords and void and the void pointer type detailing

  • spring的ioc容器的实现原理(附测试代码) 2014-03-01

    spring如今在java开源框架中大行其道,很受欢迎,是轻量级JAVA EE中的核心框架,企业级应用信息系统开发的首选框架,它不愧是是JAVA中重量级框架EJB强大挑战对手.因为其灵活的扩展性和伸缩性,灵活简单的配置(采用xml文件和Annotation注解等),可以和众多的开源框架进行有效的整合资源,让它既可以和struts,jsf这些表现层框架,也能和hibernate,ibatis这些中间件框架可以无缝链接,还有dwr这些ajax框架!总之,spring真是个神奇而又伟大的东西!而其中,

  • Jocky confusion JAVA code (to protect your JAVA project) 2010-08-05


iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.076 (s). 12 q(s)