Spring 的aop 事务不回滚
声明式事务
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="REQUIRED" /><!--之前是NOT_SUPPORT -->
<tx:method name="find*" read-only="true" propagation="REQUIRED" /><!--之前是NOT_SUPPORT -->
<tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.ArithmeticException"/>
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<!--默认其他方法都是REQUIRED -->
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="txPoint" expression="execution(* com.xeon.mis.dao.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint" />
</aop:config>
public void saveDemo() {
Demo a = new Demo();
a.setName("a");
Demo b = new Demo();
b.setName("b");
Session session = HibernateUtils.getSession();
session.save(a);
if (1 == 1)
throw new RuntimeException("运行时异常");
session.save(b);
HibernateUtils.closeSession();
}
但是还是回滚失败