Spring实现事务管理

时间:2019-11-04
本文章向大家介绍Spring实现事务管理,主要包括Spring实现事务管理使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

三种实现方式

  1.工厂模式

  2.aop

  3.注解

//公共的    .事务管理器

<bean id="Transactionmanager" class="DataSourceTransactionmanager">
   <property name="dataSource" ref="dataSource">

1.工厂模式

   1.事务管理器

   2.事务代理工厂

  

<bean id  class="TransactionProxyFactoryBean">
        指向事务管理器
        <property name=""  ref="">
        指向目标对象
         <property name=""  ref="">
        设置方法
         <property >
                <props>
                    <prop  key="方法名">传播行为,隔离空间</prop>

  TransactionD封装的四种隔离方式,七种传播行为

2.aop

  1.事务管理器

  2.调取事务管理器的方法管理目标方法的事务

  

<tx:advice id= transaction-manager="指向事务管理器">
    指定事务管理的方法
    <tx:attributes>
        <tx:method name="方法名"  isolation="事务隔离级别" propagetion="传播行为"

  将方法的事务管理与切点织入在一起

<aop:config>
    切点
    <aop:pointcut id  expression="execution(  )"
    <aop:advisor  advice-ref=" "  pointcut-ref=""/> 

3.注解

  在事务管理的方法上

  @Transaction(isolation=Isolation.隔离级别,propagetion=Propagetion.传播方法)

  ApplicationContext.xml

    //Spring 支持注解式事务配置

    <tx:annotation-driven/>

原文地址:https://www.cnblogs.com/liu13-B/p/11791506.html