Struts 2 통합 spring

필요 한 jar
인용 하 다.
    *  SPRING_HOME/dist/spring.jar
    *  SPRING_HOME/lib/jakarta-commons/commons-logging.jar
    *  SPRING_HOME/lib/log4j/log4j-1.2.15.jar
    *  SPRING_HOME/lib/aspectj/*.jar
    *  SPRING_HOME/lib/cglib/*.jar
    *  Struts2_home/lib/commons-fileupload-1.2.1.jar
    *  Struts2_home/lib/commons-io-1.3.2.jar
    *  Struts2_home/lib/freemarker-2.3.13.jar
    *  Struts2_home/lib/ognl-2.6.11.jar
    *  Struts2_home/lib/struts2-core-2.1.6.jar
    *  Struts2_home/lib/xwork-2.1.2.jar
    *  Struts2_home/lib/struts2-spring-plugin-2.1.6.jar
1. 웹. xml 파일 수정

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="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">
	<!--   spring -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:config/applicationContext.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!--   struts2 -->
	<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>
</web-app>

2. struts. 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>
	<constant name="struts.devMode" value="true" />
	<!--  struts  spring    -->
	<constant name="struts.objectFactory" value="spring" />
	
	<package name="default" namespace="/department" extends="struts-default">
		<!-- class    spring   action bean     -->
		<action name="tree" class="departmentAction" method="getTree">
			<result>/tree_list.jsp</result>
		</action>
	</package>
</struts>

3. spring 관리의 action 설정

<bean name="departmentAction" class="com.yx.zzg.action.DepartmentAction" scope="prototype">
		<property name="departmentService" ref="departmentService" />
	</bean>

좋은 웹페이지 즐겨찾기