spring事务遇到异常不回滚
测试代码:
ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
StudentDAOI studao = (StudentDAOI)app.getBean("studentDaoProxy");
studao.save(student);
save方法:
public void save(Student student) {
getHibernateTemplate().save(student);
throw new RuntimeException("aaaaaa");
}
配置如下:
<bean id="studentDaoProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<!-- <property name="proxyTargetClass">-->
<!-- <value>true</value>-->
<!-- </property>-->
<property name="proxyInterfaces">
<value>com.jwgl.vo.StudentDAOI</value>
</property>
<property name="target">
<ref bean="StudentDAO" />
</property>
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
不抛异常的时候能够正常插入数据: 抛出运行时异常是报错如下:
Exception in thread "main" java.lang.RuntimeException: aaaaaa
at com.jwgl.vo.StudentDAO.save(StudentDAO.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy1.save(Unknown Source)
at com.jwgl.test.StudentDaoTest.main(StudentDaoTest.java:24)