Objective
This blog mainly explains How spring integrates with the STRUTS2 framework ...
integration key points for Struts2 and spring :
- The action object is given to spring to create
Build the environment into the jar package
To introduce a JAR file:
- 1) Introduction of struts. Jar related files
- 2) Spring-core related jar file
- 3) Spring-web Support Jar Package
- Spring-web-3.2.5.release.jar "Spring Source"
- Struts2-spring-plugin-2.3.4.1.jar "Struts Source code"
Write config file
- Struts.xml "Struts path and action mapping configuration"
- Bean.xml "Spring IOC container Configuration"
- Xml
- "Core filter: Introducing Struts Function"
- "Initialize Spring's IOC container" to see the Spring API
Web. xml file
Web. xml file
In addition to configuring the allocator for the STRUTS2, load the spring configuration file
<?xmlVersion= "1.0" encoding= "UTF-8"?><web-appxmlns="Http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation="Http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version="3.1"> <filter> <filter-name>Struts2</filter-name> <filter-class>Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>Struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--2. Spring Configuration-- <context-param> <param-name>Contextconfiglocation</param-name> <param-value>/web-inf/classes/bean*</param-value> </context-param> <listener> <listener-class>Org.springframework.web.context.ContextLoaderListener</listener-class> </listener></web-app>
Writing a spring configuration file
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"></beans>
Writing the STRUTS2 configuration file
<?xmlVersion= "1.0" encoding= "UTF-8"?><! DOCTYPEStruts public "-//apache software foundation//dtd Struts Configuration 2.3//en" "Http://struts.apache.org/dt Ds/struts-2.3.dtd "><struts> <packagename="AAA"extends="Struts-default"> <actionname="BBB"class="Useraction"> <resultname="Success" >/2.jsp</result> </action> </package></struts>
At last
If the article is wrong, welcome to correct, we communicate with each other. accustomed to look at technical articles, want to get more Java resources of students, can pay attention to the public number: Java3y
Struts2 and Spring Integration