SpringMVC+Ibatis事务不回滚的问题

   在使用SpringMvc的时候,大多数人都会遇到事务不回滚的问题。其实事务在Spring里面使用起来很简单,只要配置正确了,知识一个标签的事。

   下面我就给大家说一下我是怎么解决这个问题的。

   一、配置扫描标签时

<!-- springmvc的配置文件中不扫描带有@Service注解的类 -->
    <context:component-scan base-package="com.dds">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
    </context:component-scan>

  二、applicationContext.xml里面关于事务的配置

   

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	     <property name="dataSource" ref="dbcpDataSource"/>
	</bean>
    <tx:annotation-driven transaction-manager="transactionManager"/> 

  三、代码使用Service的事务时注意的问题

      

@Service("permissionService")
@Transactional(rollbackFor=Exception.class)  
public class PermissionServiceImpl implements PermissionService

  在上面类直接用标签就可以了,注意,在方法里不能加try..catch,或者加上了后,在catch里面有throw new RundomException。否则事务不会回滚。

原文地址:https://www.cnblogs.com/shunxiyuan/p/4598079.html