就使用者角度來講,所謂的事務主要分兩方面:html
開啓事務:web
說明式事務:spring
Spring mvc(傳統web項目):編程
<!-- (事務管理)transaction manager, use JtaTransactionManager for global tx -->mvc
<bean id="transactionManager"框架
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">ide
<property name="dataSource" ref="dataSource" />spa
</bean>orm
<!-- 開啓聲明式事務 -->xml
<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