您好,登錄后才能下訂單哦!
在Spring Boot中,MyBatis默認(rèn)使用的是Spring的事務(wù)管理器,因此它會(huì)遵循Spring的事務(wù)隔離級(jí)別設(shè)置。Spring支持五種事務(wù)隔離級(jí)別,分別是:
要在Spring Boot中設(shè)置MyBatis的事務(wù)隔離級(jí)別,你需要在配置類中添加一個(gè)PlatformTransactionManager
bean,并設(shè)置其隔離級(jí)別。例如,如果你想將隔離級(jí)別設(shè)置為“可重復(fù)讀”,你可以這樣做:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import javax.sql.DataSource;
@Configuration
@EnableTransactionManagement
public class MyBatisConfig {
@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource) {
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
transactionDefinition.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_REPEATABLE_READ);
transactionManager.setTransactionDefinition(transactionDefinition);
return transactionManager;
}
}
這樣,你就將MyBatis在Spring Boot中的事務(wù)隔離級(jí)別設(shè)置為了“可重復(fù)讀”。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。