Skip to content

spring aop transaction

survior edited this page May 29, 2018 · 2 revisions

(1).配置示例:

<tx:advice id="txAdvice">

	<tx:attributes>

		<tx:method name="count*" propagation="SUPPORTS"

			rollback-for="" read-only="true" no-rollback-for="" />

		<tx:method name="groupCount*" propagation="SUPPORTS"

			rollback-for="" read-only="true" no-rollback-for="" />

		<tx:method name="query*" propagation="SUPPORTS"

			rollback-for="" read-only="true" no-rollback-for="" />

		<tx:method name="find*" propagation="SUPPORTS"

			rollback-for="" read-only="true" no-rollback-for="" />	

		<tx:method name="select*" propagation="SUPPORTS"

			rollback-for="" read-only="true" no-rollback-for="" />

		<tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"

			no-rollback-for="" />

	</tx:attributes>

</tx:advice>

<aop:config proxy-target-class="true">

<aop:advisor
      pointcut="execution(* com.xx.yy.server.service.impl.*Service*.*(..))"

      advice-ref="txAdvice"

      order="2" />

  <aop:aspect id="cacheClearAspect" ref="cacheClearAspect" order="1">

	  <aop:after-returning pointcut="execution(* com.xx.yy.server.service.impl.*Service*.*(..))"
						 returning="retVal"
						 method="afterReturning"/>
  </aop:aspect>

</aop:config>

<!-- 事务管理器配置, 使用jdbc事务 -->

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

<!-- 使用annotation定义事务 -->

<tx:annotation-driven transaction-manager="transactionManager"
	proxy-target-class="true" />
Clone this wiki locally