Why must the Scope of Struts2 Bean be defined when Spring and Struts2 are integrated?

Source: Internet
Author: User

Struts2 is thread-safe. By default, an instance object is created for each request, which solves the thread security problem caused by servlet to a certain extent. After the Struts2 Bean is handed over to Spring IOC for management, it uses a singleton by default. All requests use the same Action. When the Action defines some variables to accept parameters or performs verification, thread security issues often occur. For example, the Action of Struts2 is a singleton. The error information in FieldError and actionerror is accumulated, and verification cannot be performed even if the correct information is entered again. Action defines the User object, request A to submit the form, fill in the User object, and request B to determine whether the User object in the Action is empty, if it is not null, load (at this time, the User object corresponding to the B request is not loaded) and so on .... so when integrating Struts2 in Spring, remember to set the Scope of Struts2 Bean to prototype [java] @ Controller @ Scope (BeanDefinition. SCOPE_PROTOTYPE) public class UserAction extends ActionSupport {

Related Article

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.