mybatis.cfg.xml

<!DOCTYPE configuration PUBLIC "-//mybatis.org/DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd" >
<configuration>
<typeAliases>
<package name="com.lovo.sm.beans"></package>
</typeAliases>
</configuration>

applicationContext.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: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-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-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.1.xsd"> <!-- 启动@AspectJ框架的支持,如果你的项目中,
没有使用JAVA代码所写的切面,就不需要配置 -->
<aop:aspectj-autoproxy/>
<!-- 配置自动扫包规则 -->
<context:component-scan base-package="com.lovo.sm"> </context:component-scan> <!-- 配置数据源 DataSource -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- &amp;在配置文件中代表& -->
<property name="url" value="jdbc:mysql://localhost:3306/mybatis117?useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="lovo"/>
</bean> <!-- 配置Session工厂 -->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis.cfg.xml"/>
</bean> <!-- 将Mapper配置文件与Session进行关联 -->
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.lovo.sm.mapper"/>
<property name="sqlSessionFactory" ref="sqlSessionFactoryBean"></property>
</bean> <!-- 配置事务管理器 -->
<bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean> <!-- 事务管理方式一,适合于单数据库,使用注解的方式来管理事务
<tx:annotation-driven transaction-manager="dataSourceTransactionManager"/>
--> <!-- 事务管理方式二,采用springAOP来声明式的处理事务,
声明式就是脱离你的JAVA代码,通常是声明在配置中 -->
<!-- 声明一个通知 -->
<tx:advice id="txAdvice" transaction-manager="dataSourceTransactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" read-only="true"></tx:method>
<tx:method name="save*" propagation="REQUIRED" read-only="false" rollback-for="Exception"></tx:method>
<tx:method name="update*" propagation="REQUIRED" read-only="false" rollback-for="Exception"></tx:method>
<tx:method name="delete*" propagation="REQUIRED" read-only="false" rollback-for="Exception"></tx:method>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"></tx:method>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"></tx:method>
<tx:method name="search*" propagation="SUPPORTS" read-only="true"></tx:method>
</tx:attributes>
</tx:advice> <!-- 这里是配置AOP事务关联 -->
<aop:config>
<!-- 声明切入点 -->
<aop:pointcut id="serviceMethod" expression="execution(* com.lovo.sm.service.impl.*ServiceImpl.*(..))"></aop:pointcut>
<!-- 将我们定义的通知,交给AOP来关联 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"></aop:advisor>
</aop:config> </beans>

Spring、mybaits整合的更多相关文章

  1. 由“单独搭建Mybatis”到“Mybatis与Spring的整合/集成”

    在J2EE领域,Hibernate与Mybatis是大家常用的持久层框架,它们各有特点,在持久层框架中处于领导地位. 本文主要介绍Mybatis(对于较小型的系统,特别是报表较多的系统,个人偏向Myb ...

  2. JAVA springmvc+spring+mybatis整合

    一.springmvc---controller  spring----service  mybatiss---dao pring(包括springmvc).mybatis.mybatis-sprin ...

  3. Spring Boot 整合 Druid

    Spring Boot 整合 Druid 概述 Druid 是阿里巴巴开源平台上的一个项目,整个项目由数据库连接池.插件框架和 SQL 解析器组成.该项目主要是为了扩展 JDBC 的一些限制,可以让程 ...

  4. 学习spring第五天 mybatis+spring的整合(maven多模块数据查询使用了分页和连接池),以及aop

    mybatis+spring的整合: 导入的依赖:1.数据库连接:mysql-connector-java 2.连接池:druid 3.servlet:javax.servlet-api 4.jstl ...

  5. struts2 spring mybatis 整合(test)

    这几天搭了个spring+struts2+mybatis的架子,练练手,顺便熟悉熟悉struts2. 环境:myEclipse10+tomcat7+jdk1.6(1.8的jre报错,所以换成了1.6) ...

  6. 【Java EE 学习 79 下】【动态SQL】【mybatis和spring的整合】

    一.动态SQL 什么是动态SQL,就是在不同的条件下,sql语句不相同的意思,曾经在“酒店会员管理系统”中写过大量的多条件查询,那是在SSH的环境中,所以只能在代码中进行判断,以下是其中一个多条件查询 ...

  7. 3.springMVC+spring+Mybatis整合Demo(单表的增删该查,这里主要是贴代码,不多解释了)

    前面给大家讲了整合的思路和整合的过程,在这里就不在提了,直接把springMVC+spring+Mybatis整合的实例代码(单表的增删改查)贴给大家: 首先是目录结构: 仔细看看这个目录结构:我不详 ...

  8. spring+websocket整合

    java-websocket的搭建非常之容易,没用框架的童鞋可以在这里下载撸主亲自调教好的java-websocket程序: Apach Tomcat 8.0.3+MyEclipse+maven+JD ...

  9. Hibernate 与 Spring 的整合

    刚刚学习了hibernate和Spring的整合,现在来总结一下. 以实现一个功能为例,与大家分享一下整个过程. 需要实现的功能:建立一个Person类,该类包括name,sex,age,birtha ...

  10. Spring与Struts2整合VS Spring与Spring MVC整合

    Spring与Struts2整合,struts.xml在src目录下 1.在web.xml配置监听器 web.xml <!-- 配置Spring的用于初始化ApplicationContext的 ...

随机推荐

  1. Atitit  记录方法调用参数上下文arguments

    Atitit  记录方法调用参数上下文arguments 1.1. java  java8  新的对象Parameter LocalVariableTable 本地变量表 MethodParamete ...

  2. Atitit 视频编码与动画原理attilax总结

    Atitit 视频编码与动画原理attilax总结 1.1. 第一步:实现有损图像压缩和解压1 1.2. 接着将其量化,所谓量化,就是信号采样的步长,1 1.3. 第二步:实现宏块误差计算2 1.4. ...

  3. salesforce 零基础开发入门学习(九)Approval Process 介绍

    在阅读此篇文章前,可以先参考阅读一个前辈总结的关于Approval Process的操作.以下为参考的链接: http://www.cnblogs.com/mingmingruyuedlut/p/37 ...

  4. javascript_basic_01之概述

    1.javascript组成: ①核心ECMAScript:②文档对象模型DOM(Document Object Model):③浏览器对象模型BOM(Browser Object Model): 2 ...

  5. Java 线程 — ThreadLocal

    ThreadLocal 先来看看ThreadLocal的注释: This class provides** thread-local variables**. These variables diff ...

  6. js中如果省略分号那么它是如何运行的

    在javascript工作中,我们几乎不会去省略分号:为了不必要的麻烦以及代码的规范,那么如果我们省略:会发生呢?预知详情请听下回分解. 看代码! 片段一: 1 var a 2 = 3 8 4 con ...

  7. 实现CSS等分布局的4种方式

    × 目录 [1]float [2]inline-block [3]table[4]flex 前面的话 等分布局是指子元素平均分配父元素宽度的布局方式,本文将介绍实现等分布局的4种方式 思路一: flo ...

  8. QQ左侧滑动显示之按钮切换

    上一篇为大家介绍了关于自定义属性设置方法,本篇我将为大家介绍一下如何通过按钮来控制Menu的显示和隐藏,为了达到这个效果我们需要在SlidingMenu中添加三个方法,用来达到实现上述效果的目的. 我 ...

  9. hdu1962Corporative Network带权回路

    /* 有N个企业,每个企业想要实现通信,要用线路来连接,线路的长度为abs(a-b)%1000; 如果企业a 链接到了企业b 那么b就是the center of the serving! 然后有两种 ...

  10. tomcat架构之-----基本概念

    一直都没有搞明白tomcat中server.service.Engine.Host.Context概念的意义,最近认真看了<Tomcat 6 Developer Guide>,有了进一步的 ...