基于maven只整合spring和struts2


1.建好maven项目(参考:http://blog.csdn.net/tab_yls/article/details/72487287


2.在pom.xml中加入依赖。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>struts2_spring</groupId>
	<artifactId>struts2_spring</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<dependencies>
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-core</artifactId>
			<scope>compile</scope> 
			<version>2.3.24.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-spring-plugin</artifactId>
			<version>2.3.24.1</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>



3.在web.xml中加入配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>struts2_spring</display-name>
  <!-- spring -->
   <!-- 
	 如果我们想在服务器一启动就可以让spring容器自动去加载我们在配置文件中配置的bean,
	 那么我们要在web.xml中去配置一个监听器,这个监听器的作用是监听我们的application
   -->
	<listener>
	     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- 如果你的配置文件不想放在默认的位置,而是自己去指定位置,那么我们将要在web.xml中再次配置如下 -->
	<context-param>
	    <param-name>contextConfigLocation</param-name>
	    <!--指定到web-inf下面-->
	    <param-value>/WEB-INF/spring/applicationContext.xml</param-value>
	</context-param>
	
	<!-- 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>
	<welcome-file-list>
	  <welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
  
</web-app>

4.spring和struts2的配置请参考源码:http://download.csdn.net/download/tab_yls/9896449

一点说明:源码是完全可以跑起来的没有任何问题,但是只是为了整合框架,没有做过多的功能,所以运行项目之后在浏览器中输入http://localhost:8080/struts2_spring/Login就可以查看到框架已经整合成功,struts的配置文件我也想迁移位置,但是试了挺久没成功,要是有谁知道希望不吝赐教,要是在maven工程里面的

猜你喜欢

转载自blog.csdn.net/tab_yls/article/details/75019692