我们已经将 spring 版本升级到 4.3.9,升级后出现事务回滚异常
org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:125)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy65.bulkDeleteAreas(Unknown Source)
at com.nis.compass.test.functional.geocoding.GeocodingManagerTestHelper.bulkDeleteAreas(GeocodingManagerTestHelper.java:188)
这里是 bean 和父 transactionProxy bean 的 xml 配置。 我们没有更改 xml 中的任何内容,但它仍然抛出事务异常。
<bean id="geocodingManager" parent="baseTransactionProxy">
<property name="target">
<bean class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.nis.compass.geocoding.service.GeocodingManagerInternal</value>
</property>
<property name="target" ref="geocodingManagerImpl" />
<!-- list of interceptors, "Advice"s, and Advisors to add to the interceptor chain -->
<property name="interceptorNames">
<list>
<value>performanceMonitorProxy</value>
</list>
</property>
</bean>
</property>
<bean id="baseTransactionProxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="compassTransactionManager" />
</property>
<property name="transactionAttributes">
<props>
<!-- Always propagate transaction, rolling back on any checked or unchecked exception -->
<prop key="*">PROPAGATION_REQUIRED,-Throwable</prop>
</props>
</property>
<property name="preInterceptors">
<list>
<bean class="com.nis.compass.common.interceptor.ExceptionTranslationInterceptor" />
</list>
</property>
最佳答案
我认为这只是两个版本之间日志的改进。功能行为可能是相同的。
如 PROPAGATION_REQUIRED documentation 中所述,这种行为是正常的
However, in the case where an inner transaction scope sets the rollback-only marker, the outer transaction has not decided on the rollback itself, and so the rollback (silently triggered by the inner transaction scope) is unexpected. A corresponding UnexpectedRollbackException is thrown at that point. This is expected behavior so that the caller of a transaction can never be misled to assume that a commit was performed when it really was not. So if an inner transaction (of which the outer caller is not aware) silently marks a transaction as rollback-only, the outer caller still calls commit. The outer caller needs to receive an UnexpectedRollbackException to indicate clearly that a rollback was performed instead.
您还可以阅读这篇总结了文档中所写内容的相关文章:UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
关于java - spring 1.2升级到spring 4.3.9后事务回滚异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54418511/