A single case study on STRUTS2

Source: Internet
Author: User

I think we all know that struts2 default is a number of cases, and spring by default is an example, if the two integration, the action will be a singleton or a number of cases?

First, let's look at two ways to integrate STRUTS2 and spring:

1. The action is created and managed by spring, that is, by adding the @controller annotation to the action, in the case of XML, by adding the action configuration in spring, and in the Struts2 XML, The configured class directly points to the configuration classes in spring, such as

<bean id= "loginaction" class= "yaso.struts.action.LoginAction" >                     <property name= "Logindao" ref= " Logindao "/></bean>
<action name= "loginaction" class= "loginaction" >                     <result name= "Success" >/index.jsp</result> </action>

2. Create an action by struts2 yourself, and then inject the spring bean, you will not see what struts2 and Spring are related, struts2 plug-in will inject itself into the dependency, do not need to add @controller annotations on the action. It's just this way because action is out of control of spring, and if you want to use some of the features of spring, you might not.

Based on these two methods, I did an experiment, because I was annotated, the way XML is not tried, using annotations, regardless of configuration, I found that action is always a multi-instance

1. No annotations are added, action is a multi-instance

2. Only adding @controller,action is multiple cases

3. Increase @scoped (Scope.singleton) only, or multiple cases

4. Increase only @org.springframework.context.annotation.scope (Configurablebeanfactory.scope_singleton) or multiple cases

5. Increase both the scope and the scoped, as well as multiple cases

6. Add @controller and Scope, or multiple cases

Some people say that if it is XML and spring integration, and the action is generated by spring, one to add scope= "prototype", because Spring is a singleton, this I did not try, but in the annotated way, it must not be a single case, I tried.

Do not know if it is not me where the configuration has a problem, I feel that the results are unreasonable, if there are always many examples, then what is the scope of the meaning?


A single case study on STRUTS2

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.