走过路过不要错过,有钱捧个钱场,没钱捧个人场.|

志旋

园龄:4年10个月粉丝:5关注:1

Spring 声明式事务配置

Spring 声明式事务

1)spring的事务管理是通过Aop的方式来实现;

2)声明式事务是spring对事务管理的最常用的方式,因为这种方式对代码的影响最小,因此也就符合非侵入式的轻量级的容器的概念;

3)我们需要理解事务的概念,这里不再给出详细说明。

 

spring 配置文件

  <!--配置事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSources"/>
    </bean>

    <!--配置事务增强(如何管理事务,只读、读写...也就是配置事务的隔离特效)-->
  <!-- <tx:advice/>有一个transaction-manager属性,我们可以用它来指定我们的事物由谁来管理。 -->  
    <tx:advice id="interceptor" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*save*" read-only="false"/>
            <tx:method name="*get*" read-only="true"/>
        </tx:attributes>
    </tx:advice>

    <!--配置切面-aop配置,拦截哪些方法(切入点表达式,拦截上面的事务增强)-->
    <aop:config  >
        <aop:pointcut id="pointcut" expression="execution(* com.wzx.studyspringboot.SpringTxManage.*.*(..))"></aop:pointcut>
        <aop:advisor advice-ref="interceptor" pointcut-ref="pointcut"></aop:advisor>
    </aop:config>

    <!--开启注解扫描-->
    <context:component-scan base-package="com.wzx.studyspringboot.SpringTxManage"/>
    <!--开启注解事务-->
    <tx:annotation-driven></tx:annotation-driven>

 

本文作者:志旋

本文链接:https://www.cnblogs.com/wuzhixuan/p/12890677.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   志旋  阅读(54)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起