The configuration of the spring Bean's scope

Source: Internet
Author: User

Bean's scope of action:(emphasis)

The sping bean tag has a property named Scope, which is used to set the scope of the action.

scope Type values:Singleton, prototype, request, session, globalsession each of these 5 types is described below

Singleton: Singleton mode, Spring uses singleton mode by default and is the most commonly used type in development. That is, the load bean configuration file can only generate one instance of the class and will only be new once.

Prototype: Multiple cases are used once and will be new once. Because there are many objects, they are not destroyed.

Request: Applied in a Web project, Spring creates this class and then saves the class in the request scope.

Session: Applied in a Web project, Spring creates this class and then saves the class in the session scope.

Globalsession: Applied in a Web project, it must be used in a portlet environment. That is, after the data is stored in the system, there is no need to re-login under its subsystem.

Eg: QQ after the login to click on the QQ space icon, into the QQ space is not required in the QQ login.

It is not normally used.

The most used in the actual development is singleton and prototype, only in the integration of STRUCTS2 will use prototype.

Init-method the properties of the tag initialization in the Bean label, Destory-method is the property that destroys the instance.

Note: Instances can be destroyed in singleton mode only, and multi-case mode is not supported.

The configuration of the spring Bean's scope

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.