Struts-Spring
Struts-Spring整合配置图
Spring配置文件
applicationContext.xml |
<?xmlversion="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">
<importresource="applicationContext-dao.xml"/>
<importresource="applicationContext-service.xml"/>
<importresource="applicationContext-action.xml"/>
</beans> |
applicationContext-action.xml |
<?xmlversion="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-2.5.xsd">
<beanname="groupmaction"class="com.softeem.action.GroupManagerAction"> <propertyname="service"ref="gservice"> </property> </bean> </beans> |
applicationContext-service.xml |
<?xmlversion="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-2.5.xsd">
<beanname="gservice"class="com.softeem.service.impservice.GroupService"> <propertyname="dao"ref="groopservice"> </property> </bean> </beans> |
applicationContext-dao.xml |
<?xmlversion="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">
<beanname="groopservice"init-method="init"destroy-method="destroy"class="com.softeem.dao.impdao.GroupDAO"scope="prototype"> <propertyname="name"value="产品研发组"> </property>
<constructor-argtype="int"value="1000"></constructor-arg> </bean>
</beans> |
Struts配置文件
Struts.xml |
<?xmlversion="1.0"encoding="UTF-8"?> <!DOCTYPEstruts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <packagename="group"extends="struts-default"> <actionname="groupadd"class="groupmaction"> <resultname="success">success.jsp</result> </action> </package> </struts> |
Struts.properties |
struts.action.extension=do
struts.objectFactory=spring
struts.objectFactory.spring.autowire=name |
整合需导入的插件包
Web.xml配置文件
Web.xml |
<?xmlversion="1.0"encoding="UTF-8"?> <web-appversion="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext-*.xml</param-value> </context-param>
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
<filter> <filter-name>filterDispatcher</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter>
<filter-mapping> <filter-name>filterDispatcher</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> |