spring 事务配置 (二)

2014-11-24 11:30:13 · 作者: · 浏览: 18
springframework.org/schema/aop/spring-aop-3.0.xsd">

class="org.springframework.jdbc.datasource.DriverManagerDataSource">
value="com.mysql.jdbc.Driver">

value="jdbc:mysql://localhost:3306/test characterEncoding=UTF-8">



class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
value="classpath:sqlmapconfig.xml">












class="org.springframework.jdbc.datasource.DataSourceTransactionManager">



class="org.springframework.transaction.interceptor.TransactionInterceptor">



PROPAGATION_REQUIRED,-Exception



class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">


*Dao



transactionInterceptor



dao操作方法如下

public void update(String tagName ,Object obj) throws MwException
{
logger.debug("修改");
try{
this.getSqlMapClientTemplate().update(tagName,obj);
float f=1/0;
} catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//异常回滚操作
logger.debug("修改用户事务回滚了......");

}
}


三 tx:advice来配置事务,只不过有点小问题。只能对unchecked Exception进行回滚,对checked Exception 不能回滚

一下是配置,

< xml version="1.0" encoding="UTF-8" >
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-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/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

class="org.springframework.jdbc.datasource.DriverManagerDataSource">
value="com.mysql.jdbc.Driver">

value="jdbc:mysql://localhost:3306/test characterEncoding=UTF-8">



class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
value="classpath:sqlmapconfig.xml">

























dao方法:

public void update(String tagName ,Object obj) throws MwException
{
logger.debug("修改");
try{
this.getSqlMapClientTemplate().update(tagName,obj);
float f=1/0;
} catch (Exception e) {