zoukankan      html  css  js  c++  java
  • 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>
    
  • 相关阅读:
    列表标签
    超链接标签
    HTML:如何把一个无序列表转换成横向菜单
    window界面控制
    C++文件读写
    宽度,对齐方式的设置
    取出一个整数的每一位
    求两个数的最大公约数
    判断素数
    天才ACM ---待复习标志
  • 原文地址:https://www.cnblogs.com/xiaxiaopi/p/14463558.html
Copyright © 2011-2022 走看看