我们系统框架用的是struts2 + spring2.5+ibaties,在spring的配置文件中,我用aop技术控制系统的事务,但是我测试时并没有达到控制事务的作用,请大侠们帮忙看看,看是否哪里配置有问题?spring的aop配置如下:<bean id="transactionManager"  
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource" />  
</bean> <tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
 <aop:config>   
        <aop:pointcut id="serviceOpration"  
            expression="execution(* com.test.service.impl.*.*(..))"/>   
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOpration"/>   
 </aop:config>
我的TestServiceImpl 类的一个方法如下: public ReturnInfo saveOrUpdateEntityObject(Object object){
ReturnInfo info = new ReturnInfo();
try {
testDao.insert(object);
Thread.sleep(300);
System.out.println("insert 执行完毕");
testDao.update(object);
System.out.println("update 执行完毕");
Thread.sleep(500);
testDao.delete(object);
System.out.println("delete 执行完毕");
info.setFlag(true);
info.setInfo("事务控制成功");
} catch (Exception e) {
e.printStackTrace();
info.setInfo("事务控制失败");
info.setFlag(false);
}
return info;
}

解决方案 »

  1.   

    spring的事务回滚 在有在抛出 运行时异常 RuntimesException 或者error的时候才会进行事务回滚...
    如果你想让其回滚 可以在捕获错误之后主动抛出运行时异即可
      

  2.   

    <tx:method name="*" read-only="true" />
    修改
    <tx:method name="你查询数据库的业务方法名" read-only="true" />
      

  3.   

    二楼说的正确,应该在捕获异常时抛出异常,或者不要再service里面捕获异常,直接抛出即可,这样spring就能控制事务