添加事务

  1. 添加命名空间tx
  2. 创建对象
  3. 指定那一层的方法(指定需要事务管理的方法的位置
  4. 确定事务管理,哪些方法需要事务管理

从第3步开始,方法二
添加标签tx:advice
注解方法

添加命名空间tx

xmlns:tx="http://www.springframework.org/schema/tx"
 http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd

创建对象

<!--创建事务对象-->
        <bean id="tx" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                <property name="dataSource" ref="db"/>
        </bean>

指定那一层的方法(指定需要事务管理的方法的位置)

<!--确定需要事务管理的方法在什么位置-->
        <aop:config>
                <aop:pointcut id="p1" expression="execution(* com.fdk.service.impl.*.*(..))"/>
                <aop:advisor advice-ref="mytx" pointcut-ref="p1"></aop:advisor>
        </aop:config>

确定事务管理,哪些方法需要事务管理

<!--确定哪些方法需要执行事务管理-->
        <tx:advice id="mytx" transaction-manager="tx">
                <!--attributes 属性-->
                <tx:attributes>
                        <tx:method name="zhuanzhang"/>
                </tx:attributes>
        </tx:advice>

方法二
在Spring.xml文件中添加标签

<!--注解管理事务-->
    <tx:annotation-driven transaction-manager="tx"/>

在需要事务的方法或者类上面添加标签
@Transactional

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值