Spring-spring事务回滚 PROPAGATION_REQUIRES_NEW

需求定制 需求定制 主题:1050 回复:2283

Spring-spring事务回滚 PROPAGATION_REQUIRES_NEW

灵芸 发布于 2017-05-14 字数 4138 浏览 1200 回复 2

spring配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>

<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close" >
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="minPoolSize" value="${jdbc.minPoolSize}" />
<property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
<property name="initialPoolSize"
value="${jdbc.initialPoolSize}" />
<property name="maxIdleTime" value="${jdbc.maxIdleTime}" />
<property name="acquireIncrement"
value="${jdbc.acquireIncrement}" />
<property name="maxStatements" value="${jdbc.maxStatements}" />
<property name="idleConnectionTestPeriod"
value="${jdbc.idleConnectionTestPeriod}" />
<property name="acquireRetryAttempts"
value="${jdbc.acquireRetryAttempts}" />
<property name="acquireRetryDelay"
value="${jdbc.acquireRetryDelay}" />
<property name="breakAfterAcquireFailure"
value="${jdbc.breakAfterAcquireFailure}" />
<property name="maxConnectionAge"
value="${jdbc.maxConnectionAge}" />
</bean>

<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:conf/ibatis/sql-map-config.xml</value>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>

<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="pre">PROPAGATION_REQUIRES_NEW,-Exception</prop>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="proxyTargetClass" value="true" />
<property name="beanNames">
<value>*Service</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean
class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor"
ref="transactionInterceptor" />
</bean>

</beans>

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

支持 Markdown 语法,需要帮助?

评论(2

灵芸 2017-10-10 2 楼

PROPAGATION_REQUIRES_NEW是重新起一个事务,与原来的没有关系了;PROPAGATION_REQUIRED是在同一个事务里

灵芸 2017-05-17 1 楼

这个和spring的事物传播属性有关.PROPAGATION_REQUIRED属性如果调用的方法没有事务,则加入到当前事务中。也就是说调用方法和被调用方法使用同一个事务。 而PROPAGATION_REQUIRES_NEW则表示新建事务。如果当前处于事务中,则吧事务挂起。而你之所以不能回滚是由于事务被挂起而新建事务导致不是同一个事务上下文引起的