@scope Annotations in Spring

Source: Internet
Author: User
Tags sessions

The default is a single case mode, that is, scope= "singleton". The scope also has prototype, request, session, global session scope. Scope= "Prototype" in many cases

@scope default is a single case mode (singleton)

If you need to set the words @scope ("prototype")

1.singleton single case mode,

Global has and only one instance

2.prototype prototype mode,

A new instance is available each time the bean is fetched

3.request request indicates that a new bean will be generated for each HTTP demand, and that the bean is valid only within the current HTTP requests, configuration instance: request, session, global The session is used with the following configuration in the initialization Web Web.xml: If you are using a Web container of servlet 2.4 and above, Then you only need to add the following contextlistener to the XML declaration file web.xml of the Web application:

<web-app> ...
  <listener>
<listener-class>org.springframework.web.context.request.requestcontextlistener</ Listener-class>
  </listener> ...
</web-app>

4.session

The session scope indicates that a new bean is generated for each HTTP request, and that the bean is valid only within the current HTTP sessions

The

5.global session Global session scope is similar to the standard HTTP session scope, but it only makes sense in portlet-based Web applications. The Portlet specification defines the concept of a global session, which is shared by all of the different portlets that make up a portlet Web application. The bean defined in the global session scope is limited to the lifecycle scope of the globally portlet session. If you use the global session scope in the Web to identify the bean, the Web is automatically used as the type of sessions.

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.