您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

深入Spring数据库事务管理(一)

bubuko 2022/1/25 20:09:14 java 字数 3569 阅读 1755 来源 http://www.bubuko.com/infolist-5-1.html

配置事务管理器 --> 使用注解方式:使用@EnableTransactionManagement事务驱动管理器声明式事务Transactional 的配置项注意,使用声明式事务需要配置注解驱动,只要在代码清单中加入如下配置就可以使用@Transactional配置事务了:使用XML方式其实差不多,... ...

配置事务管理器

<?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方式

其实差不多,有空再写。

深入Spring数据库事务管理(一)

原文:https://www.cnblogs.com/xc-xinxue/p/12384551.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶