applicationContext-dao.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:mvc="http://www.springframework.org/schema/mvc"xmlns:p="http://www.springframework.org/schema/p"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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"><!-- 加载db.properties文件中的内容 中的key要有一定的规则 --><context:property-placeholder location="classpath:db.properties"/><!-- 配置数据源 --><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"><property name="driver" value="${jdbc.driver}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/><property name="maxActive" value="30"/><property name="maxIdle" value="5"/></bean><!-- 配置SqlSessionFactory -->    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 加载数据库连接池 --><property name="dataSource" ref="dataSource"></property><!-- 加载mybatis全局配置文件 --><property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property></bean><!-- 配置mapper扫描器 -->  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 扫描包路径,如果需要扫描多个,中间使用半角的逗号隔开 --><property name="basePackage" value="com.mybatis.mapper"></property><property name="SqlSessionFactoryBeanName" value="sqlSessionFactory"></property></bean>   </beans>

applicationContext-service.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:mvc="http://www.springframework.org/schema/mvc"xmlns:p="http://www.springframework.org/schema/p"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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"><!-- 商品管理的service --><bean id="itemsService" class="com.mybatis.service.impl.ItemsServiceImpl"></bean>
</beans>

applicationContext-transaction.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:mvc="http://www.springframework.org/schema/mvc"xmlns:p="http://www.springframework.org/schema/p"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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"><!-- 事务管理器  --><!-- 对mybatis操作数据库事务控制 spring使用jdbc的事务控制类 --><bean id="transactionManager" class="DataSourceTransactionManager"><!-- dataSource在 applicationContext-dao.xml中配置了--><property name="dataSource" ref="dataSource"></property></bean><!-- 通知 --><!-- transaction-manager 表示把这通知给谁  transactionManager就是上面的事务管理器的id--><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><!-- 传播行为 --><tx:method name="save*" propagation="REQUIRED"/><tx:method name="delete*" propagation="REQUIRED"/><tx:method name="insert*" propagation="REQUIRED"/><tx:method name="update*" propagation="REQUIRED"/><tx:method name="find*" propagation="SUPPORTS" read-only="true"/><tx:method name="get*" propagation="SUPPORTS" read-only="true"/><tx:method name="select*" propagation="SUPPORTS" read-only="true"/></tx:attributes></tx:advice><!-- aop 通知是有aop来调用  --><aop:config><!-- pointcut 表示aop的切点  --><!-- execution(* com.mybatis.service.impl.*.*(..)) 表示要切com.mybatis.service.impl这个包下面的所有类的所有方法 --><aop:advisor advice-ref="txAdvice" pointcut="execution(* com.mybatis.service.impl.*.*(..))"/></aop:config>
</beans>

SpringMvc.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:mvc="http://www.springframework.org/schema/mvc"xmlns:p="http://www.springframework.org/schema/p"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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"><!--Spring组件扫描器注解的处理器可以单个配置  但是我们可以使用spring框架的组件扫描的方式来配置base-package:需要扫描哪个包下面的处理器-->     <context:component-scan base-package="com.mybatis.controller"></context:component-scan><!-- 可代替上面注解的处理器和处理器适配器的配置 建议使用 --><mvc:annotation-driven></mvc:annotation-driven><!-- 视图解析器 --><!-- 解析jsp 默认使用jstl标签 classpath下得有jstl包 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 配置jsp路径的前缀 --><property name="prefix" value="/WEB-INF/jsp/"></property><property name="suffix" value=".jsp"></property></bean>
</beans>

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>mybatis</display-name><!-- springmvc前端控制器 --><servlet><servlet-name>mybatis</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 通过contextConfigLocation来配置springmvc加载的配置文件(处理器映射器、处理器适配器等等) --><!-- 如果不配置 contextConfigLocation 默认加载的是/WEB-INF/servler名称-servlet.xml(springmvc-servlet.xml)--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:SpringMvc.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>mybatis</servlet-name><!-- 第一种 *.action:访问以.action结尾的由DispatcherServlet进行解析 --><!-- 第二种/ :所有由DispatcherServlet进行解析 需要配置静态文件不被解析 使用此种可以实现RESTFul分割的url --><!-- 第三种/* :这样配置不对,最终要转发到一个jsp页面时,仍然会由DispatcherServlet解析jsp地址 ,不能根据jsp页面找到handler 会报错--><url-pattern>*.action</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list>
</web-app>

全部配置好之后 还需要在web.xml中加载applicationContext-*.xml(spring的配置文件)文件 包括(applicationContext-dao.xml,applicationContext-transaction.xml事务管理,applicationContext-service.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>mybatis</display-name><!-- 加载spring的配置文件 --><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/classes/spring/applicationContext-*.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- springmvc前端控制器 --><servlet><servlet-name>mybatis</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 通过contextConfigLocation来配置springmvc加载的配置文件(处理器映射器、处理器适配器等等) --><!-- 如果不配置 contextConfigLocation 默认加载的是/WEB-INF/servler名称-servlet.xml(springmvc-servlet.xml)--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/springmvc-cfg.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>mybatis</servlet-name><!-- 第一种 *.action:访问以.action结尾的由DispatcherServlet进行解析 --><!-- 第二种/ :所有由DispatcherServlet进行解析 需要配置静态文件不被解析 使用此种可以实现RESTFul分割的url --><!-- 第三种/* :这样配置不对,最终要转发到一个jsp页面时,仍然会由DispatcherServlet解析jsp地址 ,不能根据jsp页面找到handler 会报错--><url-pattern>*.action</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list>
</web-app>

转载于:https://www.cnblogs.com/mrluotong/p/5898466.html

SpringMvc和Mybatis整合需要配置的xml相关推荐

  1. springmvc和mybatis整合关键配置

    springmvc+mybaits的系统架构: 第一步:整合dao层 mybatis和spring整合,通过spring管理mapper接口. 使用mapper的扫描器自动扫描mapper接口在spr ...

  2. springMVC+Spring+mybatis整合配置版与注解版

    springMVC+Spring+mybatis整合 , 使用配置版来完成: -----------------------------前端 1.创建web系统,导入jar包: spring的jar包 ...

  3. java元婴期(29)----java进阶(springmvc(3)---springmvc和mybatis整合参数绑定(上))

    springmvc和mybatis整合 需求 使用springmvc和mybatis完成商品列表查询. 整合思路 springmvc+mybaits的系统架构: 第一步:整合dao层 mybatis和 ...

  4. SpringMVC与Mybatis整合---SpringMVC学习笔记(六)

    SpringMVC整合Mybatis的系统架构: 整合思路 第一步:整合dao层 mybatis和spring整合,通过spring管理mapper接口. 使用mapper的扫描器自动扫描mapper ...

  5. (六)springMvc 和 mybatis 整合

    目录 文章目录 @[toc] 整合 dao 层 整合 springMvc #整合思路 整合是将spring 看做是一个大的容器,将其他东西整合进来,是以 spring 为大环境的: 整合 spring ...

  6. SSM框架终极篇——Spring、SpringMVC、MyBatis整合练习(超级详细)

    SSM框架终极篇--Spring.SpringMVC.MyBatis整合练习 一.准备工作 环境: 新版IDEA MySQL 5.7 Tomcat 9.0.2 Maven 要求: 熟练掌握MySQL数 ...

  7. SpringMVC+Spring+Mybatis整合,使用druid连接池,声明式事务,maven配置

    一直对springmvc和mybatis挺怀念的,最近想自己再搭建下框架,然后写点什么. 暂时没有整合缓存,druid也没有做ip地址的过滤.Spring的AOP简单配置了下,也还没具体弄,不知道能不 ...

  8. Spring+SpringMVC+MyBatis深入学习及搭建(十四)——SpringMVC和MyBatis整合

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/7010363.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十三)--S ...

  9. mybatis学习(十一)——springmvc++spring+mybatis整合

    做任何一个项目都以一个需求,这里先定义一下需求:利用三大框架查询酒店列表. 一.搭建开发环境 1.创建一个web项目 我这里用的是 jdk1.8+tomact7.0 2.创建hotel表 CREATE ...

最新文章

  1. php和js中,utf-8编码转成base64编码
  2. Spring核心技术之IOC容器(一):IOC容器与Bean简介
  3. C++中auto关键字
  4. Hadoop配置文件
  5. java nature_Java Nature.nsf方法代码示例
  6. computed怎么使用_Vuex 基本使用
  7. [html] 写页面布局时需要考虑哪些方面的因素?
  8. 苹果应用上架,图片的要求(2017年4月27日)
  9. Django报错NameError: name ‘ListView‘ is not defined
  10. Android的ListView长按监听器
  11. 网络基础---网络层
  12. 同步虚拟机与本机的时间
  13. VHDL实现8选1数据选择器
  14. Xiangqi UVa1589
  15. DP转HDMI方案|CS5216方案应用|CS5216设计方案
  16. Win10 - 彻底禁用Cortana的方法
  17. SAP ABAP ZBA_R005获得事务代码分段,完成关键用户参数权限
  18. 用计算机算3次根号0.00005,使用ORCA在TDDFT下计算旋轨耦合矩阵元和绘制旋轨耦合校正的UV-Vis光谱...
  19. LabVIEW应用程序在Windows版本之间的字体变化
  20. 已知中序、后序,求先序

热门文章

  1. 第一个shell脚本
  2. smb(ms17-010)远程命令执行之msf
  3. IntelliJ IDEA 建空包合并问题。
  4. 扩展方法IEnumerableT转换为IListSelectListItem ,提供@Html.DropDownList使用
  5. Java并发编程:什么是线程安全,以及并发必须知道的几个概念
  6. 速看|万豪数据泄漏门再敲警钟 酒店集团7步安全建议
  7. Python自动化开发学习22-Django上
  8. kvm安装完全版 rhel6
  9. 【JAVA零基础入门系列】Day14 Java对象的克隆
  10. Linux基金会:Linux已经战胜微软