整合Struts2框架和Spring框架
-----------------------siwuxie095
整合 Struts2 框架和 Spring 框架
1、导入相关
jar 包(共 27 个)
(1)导入
Struts2 的基本 jar 包(13 个)

其中:
在
Struts2 和 Hibernate 中,都有 javassist,会产生冲突,
选择高版本,删除低版本即可
(2)导入
Spring 的核心 jar 包和日志相关的 jar 包(6 个)

Commons Logging
下载链接:
http://commons.apache.org/proper/commons-logging/download_logging.cgi
LOG4J 下载链接:
https://www.apache.org/dist/logging/log4j/
(3)导入
Spring 的 AOP 开发的 jar 包(4 个)

AOP Alliance
下载链接:
http://mvnrepository.com/artifact/aopalliance/aopalliance
AspectJ Weaver
下载链接:
http://mvnrepository.com/artifact/org.aspectj/aspectjweaver
(4)导入
Spring 的
JDBC 开发的 jar 包(2 个)

(5)导入
Spring 整合 Web 项目的 jar 包(1 个)

(6)导入
Struts2 整合 Spring 的 jar 包(1 个)

2、测试
(1)编写一个
Action 类
UserAction.java:
|
package com.siwuxie095.action; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { @Override public String execute() throws Exception { System.out.println("----- UserAction -----"); return }
} |
(2)在
Spring 核心配置文件中进行配置
applicationContext.xml:
|
<?xml <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 配置 Action 对象 --> <bean
</beans> |
(3)在
Struts2 核心配置文件中进行配置
struts.xml:
|
<?xml <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<package
<!-- 此时,class 属性对应 Spring 核心配置文件中 Bean 的 id
如果还写 Action 类的全限定名,Action 对象就会创建两次 --> <action
</package> </struts> |
(4)在部署描述文件中进行配置
web.xml:
|
<?xml <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
<filter> <!-- 配置 Struts2 的核心过滤器 --> <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>
<!-- 配置 Spring 的监听器 ContextLoaderListener --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
<!-- 配置 Spring 核心配置文件的位置(路径) --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param>
</web-app> |
(5)访问路径
http://localhost:8080/工程名/user.action
【made by siwuxie095】
整合Struts2框架和Spring框架的更多相关文章
- 整合SpringMVC框架和Spring框架
-------------------------siwuxie095 整合 SpringMVC 框架和 Spring 框架 ...
- Eclipse/JavaWeb (三)三大框架之Spring框架 持续更新中...
(一)发展历史 现在我们有三个层了,可是每层之间的调用是怎样的呢?比如显示层的struts需要调用一个业务类,就需要new一个业务类出来,然后使用:业务层需要调用持久层的类,也需要new一个持久层类出 ...
- 什么是Spring框架? Spring框架有哪些主要的模块?
Spring框架是一个为java应用程序的开发提供了综合,广泛的基础性支持的java平台.Spring帮助开发者解决了开发中基础性的问题,使得开发人员可以专注于应用程序的开发.Spring框架本身亦是 ...
- Java - Struts框架教程 Hibernate框架教程 Spring框架入门教程(新版) sping mvc spring boot spring cloud Mybatis
https://www.zhihu.com/question/21142149 http://how2j.cn/k/hibernate/hibernate-tutorial/31.html?tid=6 ...
- Java框架:spring框架整合hibernate框架的xml配置(使用注解的方式)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Java框架之spring框架的优点,为什么要学习spring框架
为什么要学习Spring的框架a: 方便解耦,简化开发 Spring就是一个大工厂,可以将所有对象创建和依赖关系维护,交给Spring管理 b:AOP编程的支持 Spring提供面向切 ...
- Spring框架学习(5)spring整合struts2
内容源自:spring整合struts2 一.spring框架对struts等表现层框架的整合原理 : 使用spring的ioc容器管理struts中用于处理请求的Action 将Action配置成i ...
- SSH框架之Spring+Struts2+Hibernate整合篇
回顾 -Hibernate框架 ORM: 对象关系映射.把数据库表和JavaBean通过映射的配置文件映射起来, 操作JavaBean对象,通过映射的配置文件生成SQL语句,自动执行.操作数据库. 1 ...
- 【Spring】Spring框架之Struts2和Spring的优点
Java Web开发使用Structs2和Spring框架的好处 今年我一直在思考web开发里的前后端分离的问题,到了现在也颇有点心得了,随着这个问题的深入,再加以现在公司很多web项目的控制层的技术 ...
随机推荐
- 学习笔记之Jira
Jira | Issue & Project Tracking Software | Atlassian https://www.atlassian.com/software/jira The ...
- Django1.7开发博客
转自: http://www.pycoding.com/articles/category/django 基于最新的django1.7写的,通俗易懂,非常适合新手入门. 感谢博主! 参考教程: htt ...
- Linux修改本地时间
1.Linux时间调整 1)安装ntp(目的同步时间) yum install ntp 2)修改文件 vi /etc/ntp.conf 添加 server ntp.sjtu.edu.cn perfer ...
- [Windows]Win10下VM虚拟机桥接模式无法上网的解决办法
Win10出来了,赶紧尝尝鲜.既然是预览版,肯定会出现以前没有过的问题.这不,问题马上就来了.我的VM虚拟机本来在Win8.1下使用桥接模式是可以上网的,但是现在不可以了.重置了好几次虚拟网络,NAT ...
- ajaxGet 获取封装
callback 表示下一个功能(回调函数) function ajaxGet(url,callback,data){ 如果路径上有参数 就在url后面拼接参数 否则只请求url ...
- 生存分析与R
生存分析与R 2018年05月19日 19:55:06 走在码农路上的医学狗 阅读数:4399更多 个人分类: R语言 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blo ...
- @Slf4j注解
参考:https://blog.csdn.net/qq_26344609/article/details/78905845 如果不想每次都写private final Logger logger = ...
- leetcode941
public class Solution { public bool ValidMountainArray(int[] A) { bool findTop = false; ) { return f ...
- HTML 表格标签
<table border="1"> <tr> <td>row 1, cell 1</td> <td>row 1, ce ...
- 前端-CSS-9-文本和字体-背景颜色
字体属性 div{ width: 300px; height: 100px; /*background-color: red;*/ border: 1px solid red; /*设置字体大小 px ...