Spring Configuration (ii): Scope of the Bean

Source: Internet
Author: User

Scope describes how the spring container creates a new instance of the bean, implemented by @scope annotations:

The spring container initially provided the scope type of two beans: Singleton and prototype, but after release 2.0, another three scope types were introduced: request, session, and global session. These three types can only be used in Web applications.
①singleton: A spring container has only one bean instance, which is the default configuration for spring. @Scope ("Singleton")
②prototype: Every time a new instance of a bean is called
③request:web project, create a new bean instance for each HTTP request
④session:web project, create a new bean instance for each HTTP session
⑤globalsession: This is intended to be useful in portal applications, creating a new bean instance for each global HTTP session
Another scope in spring batch is the use of @stepscope in batch processing.

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.