Annotations to @scope scopes in spring

Source: Internet
Author: User

@Scope simple point is to specify the scope of the bean

The official explanation is that scope is used to declare that the object in the IOC container should be in a qualified scenario or that the object's survival space, that is, before the IOC container enters the appropriate scope, the objects are generated and assembled, and the container will usually destroy the objects after they are no longer qualified for those scopes.

The default is singleton mode, where only a shared bean instance exists in the Singleton:spring IOC container, and all requests to the bean, as long as the ID matches the bean definition, will return only the same instance of the bean, and one container corresponding to the bean.

Prototype for multiple cases: each request (injecting it into another bean, or invoking the container's Getbean () method programmatically) produces a new bean instance that is equivalent to the operation

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   The representation scope indicates that a new bean is generated for each HTTP request, and that the bean is valid only within the current HTTP session for the global session  scope similar to the standard HTTP session scope, However, it only makes sense in portlet-based Web applications. The Portlet specification defines the concept of a global session, which is shared by all the various portlets that make up a portlet Web application. The bean defined in the global session scope is limited to the lifetime of the world Portlet session. If you use the global session scope to identify the bean in the Web, the Web will automatically be used as the session type to use   in the request, session, global When using the session, the first thing to do is to configure the Web. XML in the initialization website   If you are using a Web container of servlet 2.4 and above, you only need to add the following contextlistener to the XML:
< Web-app >    ...   < Listener >    < Listener-class >org.springframework.web.context.request.RequestContextListener</  Listener-class>  </listener>   ...  </web-app>

If you are Servlet2.4 a previous web container, you need to use a Javax.servlet.Filter implementation

<Web-app> .. <Filter>     <Filter-name>Requestcontextfilter</Filter-name>     <Filter-class>Org.springframework.web.filter.RequestContextFilter</Filter-class> </Filter>  <filter-mapping>     <Filter-name>Requestcontextfilter</Filter-name>     <Url-pattern>/*</Url-pattern> </filter-mapping>   ...</Web-app>

Annotations to @scope scopes in spring

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.