码迷,mamicode.com
首页 > 编程语言 > 详细

spring 事务

时间:2018-03-14 18:07:03      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:spring 事务

就使用者角度来说,所谓的事务主要分两方面:

开启事务:

说明式事务:

Spring mvc(传统web项目):

<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->

<bean id="transactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource" ref="dataSource" />

</bean>

<!-- 开启声明式事务 -->

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

Spring boot:

@EnableTransactionManagement // 启注解事务管理,等同于xml配置方式的 <tx:annotation-driven />

@SpringBootApplication

public class ProfiledemoApplication {

    // 其中 dataSource 框架会自动为我们注入

@Bean

public PlatformTransactionManager txManager(DataSource dataSource) {

return new DataSourceTransactionManager(dataSource);

}

}

编程式事务:

同说明式事务,可以优先定义TransactionTemplate, 也可以在程序中手动加载

使用事务:

说明式事务:

@Transactional

编程式事务:

TransactionTemplate:

PlatformTransactionManager:

进一步了解:

http://www.importnew.com/18332.html


spring 事务

标签:spring 事务

原文地址:http://blog.51cto.com/xinzhilian/2086833

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!