springmybatis.xml

<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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:component-scan base-package="com.scsmsjk"></context:component-scan> <!-- 引入配置文件 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties" />
</bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<!-- 初始化连接大小 连接oracle数据库无需以下配置-->
<property name="initialSize" value="${initialSize}" />
<!-- 连接池最大数量 -->
<property name="maxActive" value="${maxActive}" />
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="${maxIdle}" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${minIdle}" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${maxWait}" />
</bean> <!-- sqlSessionFactory配置 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:com/scsmsjk/mapper/*.xml"></property>
<property name="configLocation" value="classpath:sqlMapConfig.xml" />
<property name="typeAliasesPackage" value="com.nhinter.entity"/>
<!-- <property name="plugins">
<array>
分页插件配置
<bean id="paginationInterceptor" class="com.xyb2c.plugin.PaginationInterceptor"/>
</array>
</property> -->
</bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<property name="basePackage" value="com.scsmsjk.dao"></property>
</bean> <bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

service层

package com.scsmsjk.serviceImp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import com.scsmsjk.dao.TsmsHassentMapper;
import com.scsmsjk.dao.TsmsSendingMapper;
import com.scsmsjk.entity.TsmsSending;
import com.scsmsjk.service.SmsService; @Service
@Transactional(rollbackFor=Exception.class)
public class SmsServiceImp implements SmsService { @Autowired
TsmsSendingMapper tsmssendDao; @Autowired
TsmsHassentMapper tsmshassentDao; public List<TsmsSending> selectAll(){
return tsmssendDao.selectAll();
} @Transactional(propagation=Propagation.REQUIRED, isolation=Isolation.READ_COMMITTED, readOnly=false)
public int deleteByPrimaryKey(Integer fId){
int aa=tsmshassentDao.deleteByPrimaryKey(19);
int cc=aa/0;
return tsmssendDao.deleteByPrimaryKey(fId);
} }

  注意:千万不可加try{} catch(Exception erro){},否则影响事务的原子性。

spring、mybatis事务配置和控制的更多相关文章

  1. spring+mybatis事务配置(转载)

    原文地址:http://blog.csdn.net/wgh1015398431/article/details/52861048 申明式事务配置步骤 .xml文件头部需要添加spring的相关支持: ...

  2. spring mybatis 事务配置及使用

    转自:http://kinglixing.blog.51cto.com/3421535/723870

  3. spring 实现事务配置的方式

    spring 中常用的两种事务配置方式以及事务的传播性.隔离级别 一.注解式事务 1.注解式事务在平时的开发中使用的挺多,工作的两个公司中看到很多项目使用了这种方式,下面看看具体的配置demo. 2. ...

  4. spring,mybatis事务管理配置与@Transactional注解使用[转]

    spring,mybatis事务管理配置与@Transactional注解使用[转] spring,mybatis事务管理配置与@Transactional注解使用 概述事务管理对于企业应用来说是至关 ...

  5. spring,mybatis事务管理配置与@Transactional注解使用

    spring,mybatis事务管理配置与@Transactional注解使用[转]   spring,mybatis事务管理配置与@Transactional注解使用 概述事务管理对于企业应用来说是 ...

  6. spring+mybatis事务管理

    spring+mybatis事务管理 最近在和朋友做一个项目,考虑用springmvc+mybatis来做,之前在公司工作吧,对于数据库这块的配置也有人再弄,最近因为这个项目,我就上网学习了一些关于数 ...

  7. 跟着刚哥学习Spring框架--事务配置(七)

    事务 事务用来保证数据的完整性和一致性. 事务应该具有4个属性:原子性.一致性.隔离性.持久性.这四个属性通常称为ACID特性.1.原子性(atomicity).一个事务是一个不可分割的工作单位,事务 ...

  8. Spring MVC 事务配置

    Spring MVC事务配置 要了解事务配置的所有方法,请看一下<Spring事务配置的5种方法> 本文介绍两种配置方法: 一.      XML,使用tx标签配置拦截器实现事务 一.   ...

  9. [转]Spring MVC 事务配置

    Spring MVC事务配置 要了解事务配置的所有方法,请看一下<Spring事务配置的5种方法> 本文介绍两种配置方法:  <tx:advice/>就是告诉事务管理器:怎么做 ...

随机推荐

  1. 【TensorFlow】tfdbg调试注意事项

    按照网上的帖子开启tfdbg调试,可能因为没有安装curses和pyreadline包导致失败. 运行 python test001.py --debug 报错: ModuleNotFoundErro ...

  2. 【SQLServer】附加数据库失败

    一个参考:https://blog.csdn.net/zjx86320/article/details/25562361 如果类似Administrator.Everyone等都依照网上的权限改过之后 ...

  3. 1.搭建Angular2项目

    简述:搭建angular2的开发环境,网上已经有许多教程,不过都是window系统下的教程,我本人使用的是linux系统,搭建环境的过程也稍微比前者麻烦了一点,可参考本人的另一篇文章Linux系统下安 ...

  4. Asp.Net : Page.RegisterStartupScript及 不执行的原因

    RegisterStartupScript 把script放置在ASP.NET page的底部,而RegisterClientScriptBlock把script放置在ASP.NET page的顶部 ...

  5. 代码漏洞扫描描述Cross Site History Manipulation解决办法[dongcoder.com]

    代码漏洞扫描 漏洞描述:Cross Site History Manipulation 简要描述:产品的行为差异或发送不同的反应,在某种程度上暴露了与安全性相关的产品状态,例如特定的操作是否成功.可能 ...

  6. __unsafe_unretained的含义

    OC的变量限定词的官方解释: __strong is the default. An object remains “alive” as long as there is a strong point ...

  7. WindowsDenfender

    c:\Program Files\Windows Defender>MpCmdRun.exe -scan -scantype 3 -file "D:\手动更新病毒库" -Di ...

  8. [security CRT] VB实现自动下载脚本

    #$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True ' This ...

  9. git --- 持续更新

    东转西转 git 1 git 使用 1.1 git 安装 ~$: sudo apt-get install git 1.2 git 初始化 ~$: git init ~$: git remote ad ...

  10. paiza

    <?php $str1 = ('paiza'); $str2 = ('apple'); $str3 = ('letter'); function bigTower($str1, $str2, $ ...