Spring (3.2.3), spring3.2.3

Source: Internet
Author: User

Spring (3.2.3), spring3.2.3

Spring supports five scopes: singleton, prototype, request, session, and global session.

Scope Description
Singleton (Default scope) singleton mode. Each Spring IoC container will instantiate only one Bean defined by singleton.
Prototype Prototype,
Request For each HTTP request, the Bean defined by the request generates a new instance. This scope is valid only when Spring is used in Web applications.
Session For each HTTP session, a new instance is generated using the Bean defined by the session. This scope is valid only when Spring is used in Web applications.
Global session This scope is valid only when Spring is used in Web applications.

 

Singleton Scope

By default, after the Spring IoC container is started, all instances of beans defined by singleton are created and configured in singleton mode during initialization. For each configured Bean, the entire Spring container shares a unique instance. Containers track the status of Bean instances and maintain the lifecycle of Bean instances. Each time the container obtains the Bean defined by singleton, the container returns the same instance.

 

Prototype Scope

During the initialization of the Spring IoC container, instances of beans defined by prototype are not created. The container is not responsible for tracking the status of the Bean instance, nor for maintaining the lifecycle of the Bean instance. Each time you obtain an instance of the Bean defined by prototype through the container, the container creates a new instance and returns the result.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.