首页 > 编程语言 > 详细

Spring3.2与Struts2的整合环境

时间:2015-07-31 02:03:52      阅读:336      评论:0      收藏:0      [点我收藏+]

一、必要的工具

其一:Eclipse以及必要的环境就不赘述了。

其二:新建一个web工程。

?

二、必要的包(在下面可以下载)

Struts2:

(1)struts2-core-2.3.24.jar

(2)xwork-core-2.3.24.jar

(3)ognl-3.0.6.jar

(4)javassist-3.11.0.GA.jar

(5)freemarker-2.3.22.jar

(6)commons-lang3-3.2.jar

(7)commons-io-2.2.jar

(8)commons-fileupload-1.3.1.jar

(9)struts2-spring-plugin-2.3.24.jar(这个包是用来整合spring的,一定要记得加)

spring:(ps 我用的是3.2版本)

(1)spring-aop-3.2.0.M1.jar

(2)spring-asm-3.2.0.M1.jar

(3)spring-aspects-3.2.0.M1.jar

(4)spring-beans-3.2.0.M1.jar

(5)spring-context-3.2.0.M1.jar

(6)spring-core-3.2.0.M1.jar

(7)spring-context-support-3.2.0.M1.jar

(8)spring-expression-3.2.0.M1.jar

(9)spring-tx-3.2.0.M1.jar

(10)spring-web-3.2.0.M1.jar

三、必要的配置文件

关于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_2_5.xsd" id="WebApp_ID" version="2.5">
? <listener>
??<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
?</listener>
?<context-param>
??<param-name>contextConfigLocation</param-name>
??<param-value>classpath:applicationContext*.xml</param-value>
?</context-param>
??
??? <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.html</welcome-file>
??? </welcome-file-list>
?
</web-app>

一定要记得配置一个Spring提供的监听器,不然执行会报错。就是已标注为红色的部分,

我的applicationContext直接放在了src下面。个人根据放置的位置具体配置!

?

关于Struts.xml:

这个配置文件没什么好配的,关键就是在使用的使用的时候注意两点:

第一、在struts.xml配置action时,class属性写的是bean的名称!
第二、Action对象要是多例的。

?

关于applicationContext.xml

在这个里面一定要记得打开组件扫描,并定义你想扫描的包,如下:

<context:component-scan base-package="com.*.*"></context:component-scan>

对于这个文件的头部一次就全配好,以后每次配的时候直接拷贝就会比较轻松:

xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
?xsi:schemaLocation="
http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd?
http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd?
http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd?
http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">

最后如果你的xml在进行编辑的时候没有智能提示,单击eclipse下的windows--->preferences--->搜索xml catalog,选中做相应的修改就可以了。

?

???? 我只是个菜鸟,如果写得不好,不喜勿喷,最后希望能够帮助到少部分的人!

?

Spring3.2与Struts2的整合环境

原文:http://19900524.iteye.com/blog/2231771

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!