请选择 进入手机版 | 继续访问电脑版

湖南新梦想

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 420|回复: 0

spring事务管理的三种配置方式

[复制链接]

33

主题

33

帖子

190

积分

注册会员

Rank: 2

积分
190
发表于 2022-12-25 21:21:48 | 显示全部楼层 |阅读模式
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx
        https://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop
        https://www.springframework.org/schema/aop/spring-aop.xsd">
    <!--开启注解扫描-->
    <context:component-scan base-package="com.xmx.service"></context:component-scan>
    <!--导入其它xml配置-->
    <import resource="beans-datasource.xml"></import>
    <!--/////////////3.编程式事务,事务相关的bean//////////-->
    <!--事务管理,spring写好的事务黑客-->
<!--    <bean id="txManager"-->
<!--          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">-->
<!--        <property name="dataSource" ref="dataSource" />-->
<!--    </bean>-->
    <!--spring编程式事务:transactionTemplate-->
<!--    <bean id="transactionTemplate"-->
<!--          class="org.springframework.transaction.support.TransactionTemplate ">-->
<!--        &lt;!&ndash; set注入 :value注入普通属性值 ref:注入引用类型值&ndash;&gt;-->
<!--        <property name="transactionManager" ref="txManager"></property>-->
<!--    </bean>-->
    <!--/////////////4.声明式事务,事务相关的bean//////////-->
    <!--4.1目标对象通过注解扫描到bean工厂-->

    <!--4.2增强(黑客)-->
<!--        <bean id="txManager"-->
<!--              class="org.springframework.jdbc.datasource.DataSourceTransactionManager">-->
<!--            <property name="dataSource" ref="dataSource" />-->
<!--        </bean>-->
    <!--4.3.通知-->
<!--    <tx:advice id="myAdvice" transaction-manager="txManager">-->
<!--        <tx:attributes>-->
<!--            &lt;!&ndash;需要增强的方法&ndash;&gt;-->
<!--            <tx:method name="transfer"/>-->
<!--        </tx:attributes>-->
<!--    </tx:advice>-->
    <!--4.5.置入-->
<!--    <aop:config>-->
<!--        &lt;!&ndash;4.5.1切点&ndash;&gt;-->
<!--        <aop:pointcut id="myPoint" expression="execution(* com.xmx.service.impl.UserInfoServiceImpl2.*(..))"/>-->
<!--        &lt;!&ndash;4.5.2切面=切点+通知&ndash;&gt;-->
<!--        <aop:advisor advice-ref="myAdvice" pointcut-ref="myPoint"></aop:advisor>-->
<!--    </aop:config>-->

    <!--/////////////5.注解式事务,事务相关的bean//////////-->
    <bean id="txManager"
                  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                <property name="dataSource" ref="dataSource" />
            </bean>
    <tx:annotation-driven transaction-manager="txManager"></tx:annotation-driven>
</beans>
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|湖南新梦想 ( 湘ICP备18019834号-2 )

GMT+8, 2023-9-22 09:15 , Processed in 0.041003 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表