Spring3.2+mybatis3.2+Struts2.3整合配置文件大全
0.配置文件目录

1.Spring配置
applicationContext-dao.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd "> <!-- 0.连接池属性设置读取指定的properties文件 -->
<context:property-placeholder location="classpath:db.properties" /> <!-- 1.将连接池放入spring容器 -->
<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean> <!--2. 配置 Mybatis的会话工厂 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 配置Mybatis的核心 配置文件所在位置 -->
<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" />
</bean> <!-- 3.1 mapper代理配置方法一 这种方法需要大量重复的配置代理对象 MapperFactoryBean:根绝mapper接口生成代理对象
<bean id="selectUser" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="cn.qlq.core.dao.SelectUser"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property> </bean> --> <!-- 3.2通过MapperScannerConfigurer扫描进行批量生成代理对象 遵循规范:mapper.java和mapper.xml名字一样且在同一个目录下
自动扫描出来的代理对象的id为mapper类类名(首字母小写) -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 指定扫描的包名,如果有多个,用半角逗号分隔 -->
<property name="basePackage" value="cn.xm.exam.mapper"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean> <!-- 4.配置事务管理器 -->
<!-- 事务核心管理器,封装了事务操作,依赖于连接池 -->
<bean name="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean> <!-- 5.开启注解管理aop事务 -->
<tx:annotation-driven /> <!-- 事务模板对象,依赖于事务核心管理器 -->
<bean name="transactionTemplate"
class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager"></property>
</bean> <!-- ················开始使用XML管理事务························ -->
<!-- 配置事务通知(无论哪种方式都要用到事务的核心管理器) -->
<tx:advice transaction-manager="transactionManager" id="firstTx">
<tx:attributes>
<!--以方法为单位,指定方法应用事务什么属性 isolation:隔离级别 read-only:只读属性 propagation:传播行为 -->
<!-- 企业中运用通配符命名规则。两套增删改查(8种) -->
<tx:method name="save*" isolation="DEFAULT" read-only="false"
propagation="REQUIRED" />
<tx:method name="add*" isolation="DEFAULT" read-only="false"
propagation="REQUIRED" />
<tx:method name="delete*" isolation="DEFAULT" read-only="false"
propagation="REQUIRED" />
<tx:method name="remove*" isolation="DEFAULT" read-only="false"
propagation="REQUIRED" />
<tx:method name="update*" isolation="DEFAULT" read-only="false"
propagation="REQUIRED" />
<tx:method name="modify*" isolation="DEFAULT" read-only="false"
propagation="REQUIRED" />
<tx:method name="get*" isolation="DEFAULT" read-only="true"
propagation="REQUIRED" />
<tx:method name="find*" isolation="DEFAULT" read-only="true"
propagation="REQUIRED" />
</tx:attributes>
</tx:advice> <!-- 配置织入 -->
<aop:config>
<!-- 配置切点表达式 --> <aop:pointcut expression="execution(* cn.xm.exam.service.impl.*.*ServiceImpl.*(..))"
id="texPc" />
<!-- 配置切面:切点+通知 advice-ref:通知名称 pointcut-ref:切点名称 -->
<aop:advisor advice-ref="firstTx" pointcut-ref="texPc" />
</aop:config> <aop:config>
<!-- 配置切点表达式 -->
<aop:pointcut expression="execution(* cn.xm.exam.service.impl.*.*.*ServiceImpl.*(..))"
id="secondPc" />
<!-- 配置切面:切点+通知 advice-ref:通知名称 pointcut-ref:切点名称 -->
<aop:advisor advice-ref="firstTx" pointcut-ref="secondPc" />
</aop:config>
</beans>
applicationContext-service.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd "> <!-- 4.开启组件自动扫描,也就是启用注解。前提是导入spring-context-3.2.xsd约束和引入新的命名空间 -->
<context:component-scan base-package="cn.xm.exam.service"></context:component-scan> </beans>
applicationContext-action.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
<!-- 与struts2整合的配置 -->
<!-- 扫描Action基本包 -->
<context:component-scan base-package="cn.xm.exam.action"></context:component-scan> </beans>
2.Struts配置
struts.xml (主配置文件)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<constant name="struts.i18n.encoding" value="utf-8"></constant>
<constant name="devMode" value="true"></constant>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.action.extension" value="action,do" />
<constant name="struts.objectFactory" value="spring"></constant> <!-- leilong -->
<include file="struts/question.xml"></include> <!-- 乔利强引入的 -->
<include file="struts/ExamPaper.xml"></include>
<include file="struts/Exam.xml"></include>
<include file="struts/Haul.xml"></include> </struts>
Exam.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<package name="exam" namespace="/" extends="json-default,struts-default">
<!-- 全局结果集,将response转换为json传到前台 -->
<global-results>
<result name="success" type="json">
<param name="root">response</param>
</result>
</global-results> <!-- 添加考试 -->
<action name="exam_*" class="addExamAction" method="{1}"></action>
<!-- 查询考试 -->
<action name="findExam_*" class="findExamAction" method="{1}"></action>
<!--删除考试 -->
<action name="deleteExam" class="deleteExamAction"></action>
<!--修改考试 -->
<action name="UpdateExam_*" class="updateExamAction" method="{1}">
<!-- 将信息带到修改界面 (页面跳转的方式) -->
<result name="findExam">/view/examParper/exam/modifyExam.jsp</result>
<!-- 修改考试(ajax+json方式) -->
</action> <!-- 导出参考人员信息 -->
<action name="exportExamEmployees" class="extExamEmployeesAction">
<result type="stream">
<!-- 其他的参数在类中设置或者使用默认 -->
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${downloadFileName}"</param>
<param name="bufferSize">8192</param>
</result>
</action>
<!-- 导出试卷答案信息 -->
<action name="extPaperAnswer" class="extPaperAnswerAction">
<result type="stream">
<!-- 其他的参数在类中设置或者使用默认 -->
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${downloadFileName}"</param>
<param name="bufferSize">8192</param>
</result>
</action>
<!-- 导出试卷信息 -->
<action name="extPaper" class="extExamPaperAction">
<result type="stream">
<!-- 其他的参数在类中设置或者使用默认 -->
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${downloadFileName}"</param>
<param name="bufferSize">8192</param>
</result>
</action> </package>
</struts>
3.mybatis配置
SqlMapConfig.xml (主配置)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> <!-- 只需要定义个别名,这个应该有 -->
<typeAliases>
<package name="cn.xm.exam.bean.common" />
<package name="cn.xm.exam.bean.employee" />
<package name="cn.xm.exam.bean.employee.in" />
<package name="cn.xm.exam.bean.employee.out" />
<package name="cn.xm.exam.bean.exam" />
<package name="cn.xm.exam.bean.grade" />
<package name="cn.xm.exam.bean.question" />
<package name="cn.xm.exam.bean.system" />
<package name="cn.xm.exam.bean.trainContent" />
</typeAliases>
</configuration>
mapper映射配置:(要与接口放在同一目录,且名字一样)
EmployeeOutCustomMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.xm.exam.mapper.employee.out.custom.EmployeeOutCustomMapper"> <!-- S qlq -->
<!-- S 查询外部参考人员 -->
<select id="getExamEmployeeOuts" resultType="cn.xm.exam.vo.exam.ExamEmployeeOutQueryVo"
parameterType="hashmap">
SELECT
e.employeeId,
e.idcode,
e.name,
e.sex,
e.minusNum,
e.trainStatus,
u.name AS unitname
FROM employee_out e,
unit u
<where>
<include refid="getExamEmployeeOuts_where"></include>
</where>
ORDER BY u.name
</select>
<sql id="getExamEmployeeOuts_where">
<!-- 根据部门名称查询部门ID -->
<if test="1==1">
and e.unitId = u.unitId
</if>
<if test="unitNames !=null">
and e.unitId IN(SELECT
unitId
FROM unit
WHERE unit.name IN
<foreach collection="unitNames" item="unitName" separator=","
open="(" close=")">
#{unitName}
</foreach>
)
</if>
<if test="sex!=null">
and e.sex=#{sex}
</if>
<if test="idCode!=null">
and e.idCode=#{idCode}
</if>
<if test="trainStatus!=null">
and e.trainStatus=#{trainStatus}
</if>
<if test="name!=null">
and e.name like '%${name}%'
</if>
<if test="mixMinus!=null">
and e.minusNum>#{mixMinus}
</if>
<if test="maxMinus!=null">
and e.minusNum<#{maxMinus}
</if>
<!-- 如果选择进入黑名单扣分大于12 -->
<if test="isBlack!=null">
and e.minusNum>12
</if>
</sql>
<!-- E 查询外部参考人员 --> <!-- E qlq --> </mapper>
4.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>xm</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/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>
</web-app>
Spring3.2+mybatis3.2+Struts2.3整合配置文件大全的更多相关文章
- Spring3.2+mybatis3.2+Struts2.3整合
1.Spring3.2不能用于JDK1.8,只能用于JDK1.7.JDK1.8用spring4.0. 2.导入的jar包 3.目录结构: 4.配置Spring 配置数据库信息: <?xml ve ...
- Maven整合Spring3.0+Mybatis3.2+Struts2.3+查找坐标+jar包依赖(五)
依赖传递 只添加了一个struts2-core依赖,发现项目中出现了很多jar,这种情况 叫 依赖传递
- Struts2.3.4.1+Spring3.2.3+Hibernate4.1.9整合
java教程|Struts2.3.4.1+Spring3.2.3+Hibernate4.1.9整合教程并测试成功一.创建项目二.搭建struts-2.3.4.11.struts2必须的Jar包(放到W ...
- Struts2中的 配置文件
struts2中涉及到的配置文件有: web.xml.struts.xml.struts.properties.default.properties.struts-default.xml web.xm ...
- SSH框架之Spring+Struts2+Hibernate整合篇
回顾 -Hibernate框架 ORM: 对象关系映射.把数据库表和JavaBean通过映射的配置文件映射起来, 操作JavaBean对象,通过映射的配置文件生成SQL语句,自动执行.操作数据库. 1 ...
- 简易的CRM系统案例之Struts2&Spring整合+Hibernate3+JSP+MySQL版本
主要对上一篇Struts2&Spring整合的改造 简易的CRM系统案例之Struts2+Hibernate3+JSP+MySQL版本 src/bean.xml <beans xmlns ...
- Struts2的核心配置文件
Struts2的详细配置: 配置的是struts2的核心配置文件:,在struts2的核心配置文件中主要有三个标签需要进行配置:package,action,result. 1. 配置package标 ...
- Struts2 更改校验配置文件位置
@(Java)[Struts|Interceptor] Struts2 更改校验配置文件位置 在Struts2中提供的拦截器校验ValidationInterceptor,该校验器中默认的配置文件位于 ...
- Spring与Struts2 的整合使用
Spring与Struts2 的整合使用 项目结构 再Struts2 中(还没有与Spring整合时),它创建Action类的依据 <action name="second" ...
随机推荐
- Oracle的一些名词和概念
1.数据库 这里的数据库不是通常情况下我们所说的数据库,而是一个Oracle的专业名词.它是磁盘上存储数据的集合,在物理上表现为数据文件. 日志文件和控制文件等,在逻辑上以表空间形式存在.使用时,必须 ...
- js ajax 数组类型参数传递
若一个请求中包含多个值,如:(test.action?tid=1&tid=2&tid=3),参数都是同一个,只是指定多个值,这样请求时后台会发生解析错误,应先使用 tradititon ...
- Apollo源码搭建调试看一文就够
Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性,适用于微服务配置管理场景. 我 ...
- Android 给按钮添加监听事件
在安卓开发中,如果要给一个按钮添加监听事件的话,有以下三种实现方式 1.方式一 public class MainActivity extends ActionBarActivity { @Overr ...
- php中 mysql 插入特殊字符(手机端的emoji表情)出现异常
今天在用mysql存储从微信服务器拉来的数据,出现插入数据异常,报 Incorrect string value: '\xF0\x9F\x98\x97\xF0\x9F 的错误. 最终在网上查了一下,有 ...
- 从单机到2000万 QPS 并发的 Redis 高性能缓存实践之路
1.引言 知乎存储平台团队基于开源Redis 组件打造的知乎 Redis 平台,经过不断的研发迭代,目前已经形成了一整套完整自动化运维服务体系,提供很多强大的功能.本文作者陈鹏是该系统的负责人,本次文 ...
- 文档兼容性定义,使ie按指定的版本解析
作为开发人员,特别是作为Web的前端开发人员 ,最悲催的莫过于要不断的,不断的去调试各种浏览器的显示效果,而这其中最让人头痛的莫过于MS下的IE系列浏览器,在IE系列中的调试我们将会发现没有一个是好伺 ...
- 什么是混合app开发
webApp 移动app 就是在浏览器中运行的web应用 (网页应用)开发成本低 体验差 不需要安装 NativeApp :用Android和object-C原生语言开发的应用 开发成本高 需要安装( ...
- day21-5 类的多态与多态性
类的多态与多态性 多态 多态指的是一类事物有多种形态,如动物有多种形态:人.狗.猪 import abc class Animal(metaclass=abc.ABCMeta): # 同一类事物:动物 ...
- DNS隧道之DNS2TCP使用心得教程——是可以用来穿透qiang的,ubuntu下直接apt install dns2tcp
DNS隧道之DNS2TCP使用心得教程 转自:http://blog.creke.net/750.html DNS2TCP是在上次DNS隧道大检阅时提到的一个DNS隧道. 在2010年6月的更新(也是 ...