spring 整合 struts2 xml配置
整合之前要搞清楚struts2是什么;
struts2:表现层框架 增删改查 作用域 页面跳转 异常处理 ajax 上传下载 excel 调用service
spring :IOC/DI:bean容器 aop
整合点:
1.struts2的所有对象 交由spring来管理 意味着struts.xml内对象生成方式要发生改变
2.初始化容器的时机 服务器启动时完成
spring已有方案解决
整合步骤:
1.建web 工程 copy jar包
2.copy struts.xml
a:<constant name="struts.objectFactory" value="spring"/>这个是说明struts的对象交于spring来处理
b:action元素 class 属性的值 不再写包名+类名 而是写spring配置文件中的bean的id值
3.copy web.xml
监听器 启动时加载 spring的配置文件
由于监听器默认 读WEB-INF 下面名字为 applicationContext.xml的配置文件,不能读其它文件
所以需要再加一个配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
意思是读取src下所有以applicationContext开头的文件
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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>
<listener>
<!-- 此监听器默认读WEB-INF 下的applicationContext.xml 文件 启动时加载我们的spring ioc 容器 -->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- context-param 元素由 ServletContext对象解析 意思是读取src下 以applicationContext开头的所有文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
</web-app>
action:
public class TestAction {
public String execute(){
System.out.println("============TestAction===========");
return "success";
}
}
applicationContext-action.xml:
<?xml version="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-3.2.xsd" >
<bean id="testAction" class="com.huawei.s2s.action.TestAction" scope="prototype" >
</bean>
</beans>
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.objectFactory" value="spring"/>
<package name="default" namespace="/" extends="struts-default">
<action name="testAction" class="testAction" ><--注意这里class的值-->
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
spring 整合 struts2 xml配置的更多相关文章
- spring 整合 hibernate xml配置
spring 整合 hibernate: hibernate :对数据库交互 spring: ioc aop 整合点: 1.sessionFactory对象不再由hibernate生成,交由spr ...
- Spring整合Struts2 XML版
1.jar包 <!--spring配置--> <dependency> <groupId>org.springframework</groupId> & ...
- Spring整合Struts2的配置与测试
整合目的 让Spring的IOC容器管理Struts2的Action 整合步骤 1.新建一个Web项目 2.加入Spring的jar包和添加Spring的配置文件 3.在Web.xml中配置Conte ...
- 一 SSH整合:Spring整合Struts2的两种方式,struts.xml管理Action&Bean管理Action
SSH回顾 1 引入jar包 Struts2的jar包 D:\Struts2\struts-2.3.35\apps\struts2-blank\WEB-INF\lib 开发基本包 Struts2有一 ...
- Struts2的使用以及Spring整合Struts2
一.如何单独使用Struts2 (1)引入struts2的jar包 commons-fileupload-1.2.1.jar freemarker-2.3.15.jar ognl-2.7.3.jar ...
- Spring整合Struts2框架的第二种方式(Action由Spring框架来创建)(推荐大家来使用的)
1. spring整合struts的基本操作见我的博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2框架整 ...
- Spring整合Struts2框架的第一种方式(Action由Struts2框架来创建)。在我的上一篇博文中介绍的通过web工厂的方式获取servcie的方法因为太麻烦,所以开发的时候不会使用。
1. spring整合struts的基本操作见我的上一篇博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2 ...
- Spring框架学习(5)spring整合struts2
内容源自:spring整合struts2 一.spring框架对struts等表现层框架的整合原理 : 使用spring的ioc容器管理struts中用于处理请求的Action 将Action配置成i ...
- Spring整合Struts2的方法
一.基本支持 通常我们整合Spring和struts2的目的是让Spring来管理struts2的控制器.也就是说把Action交由Spring来管理,利用IOC的特性把Action注入到业务逻辑中. ...
随机推荐
- SiteMap Editor for Microsoft Dynamics CRM 2011 使用说明
How to connect to CRM environments using this tool If you already connected to a CRM deployment usin ...
- 2017头条笔试题:二维点集中找出右上角没有点的点并按x坐标从小到大打印坐标
PS:这篇是之前本来就想发的但是一直没时间写,加上今天做了京东的题,结果代码名就命名为jingdong了……懒得改代码名重新跑一遍结果了=.= 暴力法去做就是遍历每个点,判断它是不是“最大点”.判断过 ...
- 13.MD5对用户密码进行加密
MD5概述 用户名密码保存在客户端是一种十分危险的行为.所以需要进行加密后保存. 其中MD5就是一种比较常用的加密算法. 与其说MD5算法是一种加密算法,不如说是一种数据指纹(数据摘要)算法. 其特点 ...
- 杂项-TOOL:NPIO
ylbtech-杂项-TOOL:NPIO NPOI是指构建在POI 3.x版本之上的一个程序,NPOI可以在没有安装Office的情况下对Word或Excel文档进行读写操作.NPOI是一个开源的Ja ...
- [转]my97 datepicker IE9+ 故障修复方法
转自:http://blog.csdn.net/xuwj1984/article/details/38733483 问题1:my97 datepicker 不能弹出日期下拉框. 解决方法: 1.下载最 ...
- Java与C++语法的区别
1. 注释可以在Java程序中起到文档标记的作用 类文档标记: 1)@version 2)@author 3)@param 4)@return 5)@exception 2. Java的字符占两个字节 ...
- python输出格式化及函数format
格式 描述%% 百分号标记%c 字符及其ASCII码%s 字符串%d 有符号整数(十进制)%u 无符号整数(十进制)%o 无符号整数(八进制)%x ...
- 香侬科技独家对话Facebook人工智能研究院首席科学家Devi Parikh
Facebook 人工智能研究院(FAIR)首席科学家 Devi Parikh 是 2017 年 IJCAI 计算机和思想奖获得者(IJCAI 两个最重要的奖项之一,被誉为国际人工智能领域的「菲尔兹奖 ...
- 转载:关于java关键字transient
今天在map源码中看到这个关键字 百度看一下 转载记录下 源文:http://www.cnblogs.com/lanxuezaipiao/p/3369962.html 1. transient的作 ...
- python作用域与LEGB规则
作用域 什么是命名空间 比如有一个学校,有10个班级,在7班和8班中都有一个叫“小王”的同学,如果在学校的广播中呼叫“小王”时,7班和8班中的这2个人就纳闷了,你是喊谁呢!!!如果是“7班的小王”的话 ...