spring 声明式事务

隔离级别,isolotion
default 默认为:read_commited
read_uncommited 有脏读,不可重复读,幻像读问题
read_commited 有不可重复读,幻像读问题
repeatable_read 有幻像读问题
serializable 有性能问题

传播行为:propagation behavi
required有事务加入事务,没有则新建事务
required_new新建事务,如果当前存在事务,则挂起当前事务
mandatory有事务加入事务,没有则抛出异常
never以非事务方式处理,有事务则抛出异常
supports有事务加入事务,没有以非事务方式处理
not_supports以非事务方式处理,当前存在事务则挂起当前事务
nested 当前无事务时相当于required

 

基于TransactionInterceptor 的声明式事务管理
基于 TransactionProxy... 的声明式事务管理
基于 <tx> 命名空间的声明式事务管理
基于 @Transactional 的声明式事务管理

 

==========基于 TransactionProxy... 的声明式事务管理==========

<beans>

 <bean id="bankServiceTarget" class="footmark.spring.core.tx.declare.classic.BankServiceImpl">
  <property name="bankDao" ref="bankDao"/>
 </bean>
 
 <bean id="bankService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="target" ref="bankServiceTarget"/>

  <property name="transactionManager" ref="transactionManager"/>

  <property name="transactionAttributes">
   <props>
    <prop key="transfer">PROPAGATION_REQUIRED</prop>
   </props>
  </property>
 </bean>

</beans>

 

==========基于TransactionInterceptor 的声明式事务管理==========

<beans>

 <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <property name="transactionManager" ref="transactionManager"/>
  
  <property name="transactionAttributes">
   <props>
    <prop key="transfer">PROPAGATION_REQUIRED</prop>
   </props>
  </property>
 </bean>


 <bean id="bankServiceTarget" class="footmark.spring.core.tx.declare.origin.BankServiceImpl">
  <property name="bankDao" ref="bankDao"/>
 </bean>

 <bean id="bankService" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="target" ref="bankServiceTarget"/>
  <property name="interceptorNames">
  <list>
  <id ref bean="transactionInterceptor"/>
  </list>
  </property>
 </bean>

</beans>

 

==========基于 <tx> 命名空间的声明式事务管理==========

<beans>

 <bean id="bankService" class="footmark.spring.core.tx.declare.namespace.BankServiceImpl">
  <property name="bankDao" ref="bankDao"/>
 </bean>

 <tx:advice id="bankAdvice" transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method name="transfer" propagation="REQUIRED"/>
  </tx:attributes>
 </tx:advice>
 
 <aop:config>
  <aop:pointcut id="bankPointcut" expression="execution(* *.transfer(..))"/>
  <aop:advisor advice-ref="bankAdvice" pointcut-ref="bankPointcut"/>
 </aop:config>

</beans>


<beans>

 <bean id="bankService" class="footmark.spring.core.tx.declare.namespace.BankServiceImpl">
  <property name="bankDao" ref="bankDao"/>
 </bean>

 <tx:advice id="bankAdvice" transaction-manager="transactionManager">

 <aop:config>
  <aop:pointcut id="bankPointcut" expression="execution(**.transfer(..))"/>
  <aop:advisor advice-ref="bankAdvice" pointcut-ref="bankPointcut"/>
 </aop:config>

</beans>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值