zoukankan      html  css  js  c++  java
  • 深入Spring数据库事务管理(一)

    配置事务管理器

    <?xml version='1.0' encoding='UTF-8' ?>
    <!-- was: <?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:p="http://www.springframework.org/schema/p"
        xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
           http://www.springframework.org/schema/context 
           http://www.springframework.org/schema/context/spring-context-4.0.xsd">
    <!--启用扫描机制,并指定扫描对应的包-->
        <context:annotation-config />
        <context:component-scan base-package="com.ssm.chapter13.*" />
    
    <!-- 事务管理器配置数据源事务,注意是因为使用MyBatis才使用这个数据源 -->
        <bean id="transactionManager"
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource" />
        </bean>
    
        <!-- 使用注解定义事务 -->
        <tx:annotation-driven transaction-manager="transactionManager" />
    
    </beans>

    使用注解方式:使用@EnableTransactionManagement事务驱动管理器


    声明式事务

    Transactional 的配置项

    2020-02-29_182111

    注意,使用声明式事务需要配置注解驱动,只要在代码清单中加入如下配置就可以使用@Transactional配置事务了:

    <tx:annotation-driven transaction-manager="transactionManager"/>

    使用XML方式

    其实差不多,有空再写。

  • 相关阅读:
    微信小程序订阅消息
    自动生成小学四则运算题目
    个人项目作业
    自我介绍+软工5问
    软件工程之获小黄衫感言
    2020软件工程个人作业06——软件工程实践总结作业
    2020软件工程作业05
    2020软件工程作业00——问题清单
    2020软件工程作业04
    2020软件工程作业03
  • 原文地址:https://www.cnblogs.com/xc-xinxue/p/12384551.html
Copyright © 2011-2022 走看看