For SPRINGMVC Controller Singleton and multiple examples, here is an example of the following. First: The class is a multi-instance, a normal property and a static property.
Result: General properties: 0 ....... Static properties: 0 Normal properties: 0 ...... Static properties: 1 Normal properties: 0 ...... Static properties: 2 Normal properties: 0 ...... Static properties: 3 Therefore, for the common properties of multiple cases, it will not be shared and will not have an effect, and the property will be shared for static properties. Second time: class changed to single case
Result: General properties: 0 ....... Static properties: 0 Normal properties: 1 ...... Static properties: 1 Normal properties: 2 ...... Static properties: 2 Normal properties: 3 ...... Static properties: 3 So the common and static properties are shared for a single case. Third: Classes Remove @scope annotations
Result: General properties: 0 ....... Static properties: 0 Normal properties: 1 ...... Static properties: 1 Normal properties: 2 ...... Static properties: 2 Normal properties: 3 ...... Static properties: 3 Therefore, SPRINGMVC is a singleton by default. In addition print in other methods
The result of the output is
Jumping to another method does not go to the initial value, but to share the property. In the end: Try not to define the attribute in the controller, if you need to define the attribute in special cases, then add the annotation @scope ("prototype") on the class to the pattern of multiple cases, the former struts is based on the properties of the class to send, Defining properties can be common to the whole class, so the default is a number of cases, or the multi-threaded access is definitely the property value of the common class, it is certainly unsafe, but Springmvc is based on the method of development, are used to receive the value of parameters, a method to end the parameter is destroyed, multi-threaded access will have a memory space to produce The parameters inside are not shared, and all SPRINGMVC default to a singleton, so it is not appropriate for the controller to define attributes within the class, as long as the controller does not define the attributes, then the singleton is completely safe. Springmvc This design is the main reason is to improve the performance of the program and later maintenance of the program only for the maintenance of the line, if the properties of the struts are more defined, do not know which method used this property, the maintenance of the program is still very troublesome
SPRINGMVC Controller single case and multiple cases