• Spring 中的事务配置


    Spring 中的事务配置

    <?xml version="1.0" encoding="UTF-8"?>
    <!--suppress ALL -->
    <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:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/aop/spring-tx.xsd">
    
        <import resource="spring-mybatis.xml"></import>
    
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <constructor-arg ref="dataSource" />
        </bean>
    
        <!--sqlSessionFactory:使用spring数据源替换mybatis-->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="mapperLocations" value="com/xia/mapper/*.xml"></property>
            <property name="typeAliases" value="com.xia.pojo.User"></property>
        </bean>
        <!--    data sources-->
        <bean id="dataSource"  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
            <property name="url" value="jdbc:mysql://localhost:3306/sm?useSSL=true&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=UTC"></property>
            <property name="username" value="root"></property>
            <property name="password" value="123456"></property>
        </bean>
        <!--获得sqlSession-->
        <!--    IOC配置-->
        <context:component-scan base-package="com.xia"></context:component-scan>
        <context:annotation-config/>
        
    <!--    aop实现事务的织入-->
    <!--    配置事务通知-->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
    <!--            给哪些方法配置事务-->
                <tx:method name="add" propagation="REQUIRED"/>
            </tx:attributes>
        </tx:advice>
    <!--   配置事务切入-->
        <aop:config>
            <aop:pointcut id="txPointCut" expression="execution(* com.xia.mapper.*.*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"></aop:advisor>
        </aop:config>
    </beans>
    
  • 相关阅读:
    简单的验证码;在一个数组中随即打印出4个不重复的字母
    数据类型
    java语法基础
    mac 开机运行脚本
    【mac】 搭建java环境
    mac 复制文件到NTFS格式的移动硬盘
    JAVA学习日报 8.19
    JAVA学习日报 8.20
    (VI)事务:Spring 事务管理
    (VI)事务:Spring 事务细节
  • 原文地址:https://www.cnblogs.com/xiaxiaopi/p/14463558.html
Copyright © 2020-2023  润新知