0 0

spring+ibatis 多数据源事务不回滚0

以下代码我的事务配置:

<!-- 事务拦截1 -->  
<bean id="transactionInterceptorProduct" class="org.springframework.transaction.interceptor.TransactionInterceptor">  
    <property name="transactionManager" ref="transactionManagerProduct" />  
    <property name="transactionAttributes">  
    <props>  
        <prop key="save">PROPAGATION_REQUIRED</prop>  
        <prop key="insert*">PROPAGATION_REQUIRED</prop>  
        <prop key="delete*">PROPAGATION_REQUIRED</prop>  
        <prop key="update*">PROPAGATION_REQUIRED</prop>  
        <prop key="do*">PROPAGATION_REQUIRED</prop>  
    </props>  
    </property>  
</bean>  
<!-- 事务拦截2 -->  
 <bean id="transactionInterceptorBbs" class="org.springframework.transaction.interceptor.TransactionInterceptor">  
     <property name="transactionManager" ref="transactionManagerBbs" />  
     <property name="transactionAttributes">  
     <props>  
         <prop key="save">PROPAGATION_REQUIRED</prop>  
         <prop key="insert*">PROPAGATION_REQUIRED</prop>  
         <prop key="delete*">PROPAGATION_REQUIRED</prop>  
         <prop key="update*">PROPAGATION_REQUIRED</prop>  
         <prop key="do*">PROPAGATION_REQUIRED</prop>  
     </props>  
     </property>  
 </bean>     

<!--  管理你连接的地方-->  
<bean id="autoProxyCreator" abstract="true" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">  
    <property name="beanNames"> 
    <list> 
     <value>holdProductManager</value>  
     <value>tipManager</value>  
    </list>
    </property>  
    <property name="interceptorNames">  
        <list>  
        <value>transactionInterceptorProduct</value>  
        <value>transactionInterceptorBbs</value>  
        </list>  
    </property>  
</bean>  

 

我在 holdProductManager bean 中的一个方法里面报出异常,发现事务不回滚。代码如下:

@Override
public void doTranTest() throws Exception{
	HoldProduct obj = new HoldProduct();
	obj.setProductCname("多数据的配置测试");
	obj.setProductCode("sldke sdei 123");
	holdProductDao.save(obj);
	tipDao.get(1L); 
	if (1 ==1) {
		throw new RuntimeException("2356");
	}
}

 

请问spring+ibatis 的多数据事务,应该怎么样配置呢 ?

 

2012年12月16日 10:02

2个答案 按时间排序 按投票排序

0 0

跨数据源的事务要用jta事务的,不然无法回滚

2012年12月16日 12:13
0 0

@Override
public void doTranTest() throws Exception{
HoldProduct obj = new HoldProduct();
obj.setProductCname("多数据的配置测试");
obj.setProductCode("sldke sdei 123");
holdProductDao.save(obj);
tipDao.get(1L);
if (1 ==1) {
throw new RuntimeException("2356");
}
}

你这段测试代码需要加事务的, 否则这段代码是无事物的。异常对之前的操作无影响

具体配置请参考
http://jinnianshilongnian.iteye.com/blog/1469524

2012年12月16日 10:16

相关推荐

Global site tag (gtag.js) - Google Analytics