Struts2 + spring integration framework
1. Copy the struts2-spring-plugin-x-x-x.jar and the corresponding spring. jar to the/WEB-INF/lib directory. Struts2-spring-plugin-x-x-x.jar in struts2 lib, x-x is version 2. in struts. set struts in properties. objectFactory attribute value struts. propertiesstruts. objectFactory = spring or configure struts as a constant in the XML file. xml <struts> <constant name = "struts. objectFactory "value =" spring "/> </struts> 3. in the web. add Spring context parameters and listeners in xml format <! -- Used to locate the context configuration of the Spring XML file --> <context-param> <param-name> contextConfigLocation </param-name> <param-value>/WEB-INF/applicationContext -*. xml, classpath *: applicationContext -*. xml </param-value> </context-param> web. xml <listener> <listener-class> org. springframework. web. context. contextLoaderListener </listener-class> </listener> 4. modify the Struts configuration file. xml <? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE struts PUBLIC "-// Apache Software Foundation // DTD Struts Configuration 2.0 // EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <! -- Set struts. objectFactory property value --> <constant name = "struts. objectFactory "value =" spring "/> <package name =" struts-config "namespace ="/"extends =" struts-default "> <action name =" login "class = "loginAction" <result name = "frame">/frame. jsp </result> </action> </package> </struts> applicationConext. xml <? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: p = "http://www.springframework.org/schema/p" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean name = "loginAction" class = "com. system. action. loginAction "scope =" prototype "> </bean> </beans> struts. in the xml file, the class attribute in <action name = "" class = ""> is changed from the class path to the custom class name applicationConext. <bean name = "Custom Class name (same as struts. the class definition in the xml file is the same.) "class =" class path "> 5. now, your Struts2 and Spring can work normally together.