1.Mysql数据库表是否支持事务,查看表的类型是MyISAM 还是 InnoDB(支持事务)
2.确保第一点
3.只要配置片段
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!--当代理的service层中的方法抛出异常的时候才回滚,必须加rollback-for参数-->
<tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="del*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>
<!--除了上面标识的方法,其他方法全是只读方法-->
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config expose-proxy="true">
<aop:pointcut id="txPointcut"
expression="execution(* com.sjzh.ssm.service..*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>