The scope property of the bean in spring is understood

Source: Internet
Author: User

The scope property of the bean is Prototype,singleton,request, and several properties of the session

When spring and struts2 are integrated, the STRUTS2 action is configured to scope= "prototype", which is for thread safety,

The following is part of the struts2+hibernate+spring configuration file, which used to mimic the configuration of a well-written bean. Once Scope= "prototype" forgot to write the result of the problem, its default is scope= "Singleton", the only.
Additions to a table in the project the action is to use an action, the action has add,update,delete,save these methods, add and modify is to share a page, when the page gets the ID of the modification operation, and vice versa is the add operation. Because the bean in the configuration spring is forgetting to write scope= "prototype", the last visited record is displayed each time it is added.
For a long time, it turned out that the spring Bean was out of the question. Scope= "prototype" creates a new action object when the object of that type is requested. If you do not configure scope=prototype, you will not create a new action when you add it, and he will leave the last logged-on information.
<bean id= "assetaction" class= "Com.servicezone.itsd.asset.webapp.action.AssetAction" scope= "prototype">

Since the action is configured with scope= "prototype", the bean in action cannot be configured as scope= "Request, otherwise it will be an error: org.springframework.beans.factory.beancreationexcepti On:error creating bean with Name ' customer ': Scope ' request ' isn't active for the current thread; Consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; Nested exception is Java.lang.IllegalStateException:No thread-bound request Found:are your referring to request attribute s outside of an actual Web request, or processing a request outside of the originally receiving thread? If you be actually operating within a Web request and still receive this message, your code is probably running outside O F Dispatcherservlet/dispatcherportlet:in This case, use Requestcontextlistener or requestcontextfilter to expose the Curr ENT request.

It's also understandable that action is new every time, but the property inside is not

The scope property of the bean in spring is understood

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.