Spring's scope scope

Source: Internet
Author: User

In spring, there are five types of beans in scope: The default is singleton mode,

Singleton

Prototype

Request

Session

Global session

When configuring scopes, using the Scope property, the XML file is configured as follows

To view the official spring documentation, explain the following:

1, Singleton

If a bean is configured as Singelton, it indicates that the bean has only one instance in the spring IOC container, that is, a singleton

The configuration is as follows: The following two configurations are the same, using singleton by default

You can create a new spring project for testing: Observe whether the return is true or false

2, prototype

Prototype-scoped Bean, each request produces a new Bean instance, equivalent to the operation of

For a new instance of prototype, the spring container does not perform his life cycle callback method and can refer to the Spring life cycle document I wrote.

The Spring official documentation explains the following

3. Request, session, and global session scopes these three scopes are mainly used in the Web,

Request: Indicates that a new bean will be generated for each HTTP request, and that the bean is valid only within the current HTTP requests

Session: Indicates that a new bean will be generated for each HTTP request, and that the bean is valid only within the current HTTP session

Global session: Indicates that a new bean will be generated for each HTTP request, but it only makes sense in a portlet-based web application

Spring's scope scope

Related Article

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.