Whether the action of struts2 is the default singleton mode or multi-case mode, and the default multi-case mode or single-case mode of springMVC's controller

Struts2 Action is a single case or multiple cases?

Is Spring's controller singleton or multiple by default?

1. Default singleton

SpringMVC is singleton by default. Unlike Struts2, SpringMVC does not have a default processing method, which means that SpringMVC is based on method development. It uses formal parameters to receive values. When a method ends, the parameters are destroyed. Multi-threaded access will generate a memory space, and the parameters inside are also will not be shared. Since SpringMVC uses a singleton by default, it is not suitable to define properties in the Controller class. As long as no properties are defined in the controller, the singleton is completely safe. The singleton pattern can improve SpringMVC performance without the need to create an object for each corresponding request.

Additionally, Spring's Ioc container-managed beans are single-instance by default .

2. Multiple cases

In special cases, when you need to define properties in the Controller class, the singleton will definitely have competing access, and you need to add the annotation @Scope("prototype") to the class to change to the multi-instance mode.

3、Struts2

Unlike SpringMVC, Struts2 is based on class attributes, and the defined attributes can be common to the entire class. Therefore, the Action of Struts2 is multi-instance not a singleton, that is, an object of Action is generated for each request. The Action class often contains data attributes, such as the fields of the form filled in the page, and there are corresponding attributes in the Action to bind the page form fields. Obviously, if the Action is a single instance, it will affect each other in a multi-threaded environment, such as causing the data filled in by others to be seen by you.

But what does someone say that the Action of Struts2 is a singleton by default? And can it be configured? 
Because when used with Spring, Action is managed by Spring, and the default is singleton, so some people say that Struts2 is singleton by default. 
So when Spring integrates Struts2 development, if you need to use Str

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324735587&siteId=291194637