1, the integration of Spring and STRUTS2 purposes:
Let Spring manage instances of Action (multiple cases);
Easy injection of dependent objects.
Add Struts2-spring-plugin-2.1.8.jar, responsible for spring management object Dependency Injection
2, the integration of the steps:
Spring is used in a Web project to configure a listener to create a ApplicationContext object;
Add Struts2-spring-plugin.jar to get struts2 to take the action object from the Spring container.
3, in the Web.xml
<!--Configure spring's listener for initializing ApplicationContext objects-->
<listener>
<listener-class> org.springframework.web.context.contextloaderlistener</listener-class>
</listener>
< context-param>
<param-name>contextConfigLocation</param-name>
<param-value> Classpath:applicationcontext*.xml</param-value>
</context-param>
4, testing, in the Testaction.java
@Controller
public class testaction extends actionsupport{
@Resource
Private testservice testservice;
Public String execute () throws exception{
s.o.p ("---------> testservice:" + Testservice;);
Return "Success";
}
5. Adjust Struts.xml
<package name= "Default" namespace= "/" extends= "Struts-default" >
<!--Configure the action for the test-->
< Action name= "Test" class= "testaction" method= "Testservice" >
<result name= "Success" >/test.jsp</ result>
</action>
</package>
Results: Access to Localhost:8080/itcastoa/test.do
If S.O.P ("---------> Testservice:" + testservice;); The testservice in is not NULL, which means success.
Above, the three major framework integration completed.
When you change only the method body, you do not need to republish. Re-publish the method name when you change it.