修改单数据源seata结合方式以及修改文档

This commit is contained in:
life 2023-08-08 22:47:27 +08:00
parent 2d2e172b5b
commit 48aaad3b6c
6 changed files with 12 additions and 61 deletions

View File

@ -238,3 +238,12 @@ seata:
<version>1.7.0</version>
</dependency>
```
### 事例
请到mybatis-flex-test模块下面
```xml
mybatis-flex-spring-boot-seataflex多数据源与seata的结合
```
```xml
mybatis-flex-spring-boot-seata-demo:官方demo与flex结合
```

View File

@ -226,12 +226,8 @@ public class MybatisFlexAutoConfiguration implements InitializingBean {
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
FlexSqlSessionFactoryBean factory = new FlexSqlSessionFactoryBean();
SqlSessionFactoryBean factory = new FlexSqlSessionFactoryBean();
factory.setDataSource(dataSource);
if (properties.getSeataConfig() !=null && properties.getSeataConfig().isEnable()){
factory.setSeata(true);
factory.setSeataMode(properties.getSeataConfig().getSeataMode());
}
if (properties.getConfiguration() == null || properties.getConfiguration().getVfsImpl() == null) {
factory.setVfs(SpringBootVFS.class);
}

View File

@ -154,21 +154,6 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean
private ObjectWrapperFactory objectWrapperFactory;
private boolean seata = false;
private SeataMode seataMode = SeataMode.AT;
public void setSeata(boolean seata) {
this.seata = seata;
}
public void setSeataMode(SeataMode seataMode) {
this.seataMode = seataMode;
}
/**
* Sets the ObjectFactory.
*
@ -615,16 +600,6 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean
// fixed https://gitee.com/mybatis-flex/mybatis-flex/issues/I70QWU
// 兼容SpringManagedTransactionFactory否则在使用JdbcTemplate,多数据源使用JdbcTemplate报错
//fixed https://gitee.com/mybatis-flex/mybatis-flex/issues/I7HJ4J
// 兼容单数据源seata
if (!(dataSource instanceof FlexDataSource)){
if (seata){
if (seataMode == SeataMode.XA){
dataSource = new DataSourceProxyXA(dataSource);
}else {
dataSource = new DataSourceProxy(dataSource);
}
}
}
targetConfiguration.setEnvironment(new Environment(this.environment,
// this.transactionFactory == null ? new SpringManagedTransactionFactory() : this.transactionFactory,
// this.transactionFactory == null ? new JdbcTransactionFactory() : this.transactionFactory,

View File

@ -1,14 +1,5 @@
server:
port: 8083
mybatis-flex:
seata-config:
enable: true #启动seata
seata-mode: XA #xa或者ta
# datasource:
# accountdb:
# url: jdbc:mysql://127.0.0.1:3306/db_account
# username: root
# password: 131496
spring:
main:
allow-circular-references: true
@ -21,8 +12,6 @@ seata:
enabled: true
application-id: account-service
tx-service-group: my_test_tx_group
enable-auto-data-source-proxy: false
#use-jdk-proxy: false
client:
rm:
async-commit-buffer-limit: 1000

View File

@ -1,14 +1,5 @@
server:
port: 8082
mybatis-flex:
seata-config:
enable: true #启动seata
seata-mode: XA #xa或者ta
# datasource:
# orderdb:
# url: jdbc:mysql://127.0.0.1:3306/db_order
# username: root
# password: 131496
spring:
main:
allow-circular-references: true
@ -21,7 +12,7 @@ seata:
enabled: true
application-id: order-service
tx-service-group: my_test_tx_group
enable-auto-data-source-proxy: false
# enable-auto-data-source-proxy: false
#use-jdk-proxy: false
client:
rm:

View File

@ -1,14 +1,5 @@
server:
port: 8081
mybatis-flex:
seata-config:
enable: true #启动seata
seata-mode: XA #xa或者ta
# datasource:
# stockdb:
# url: jdbc:mysql://127.0.0.1:3306/db_stock
# username: root
# password: 131496
spring:
main:
allow-circular-references: true
@ -21,7 +12,7 @@ seata:
enabled: true
application-id: stock-service
tx-service-group: my_test_tx_group
enable-auto-data-source-proxy: false
# enable-auto-data-source-proxy: false
#use-jdk-proxy: false
client:
rm: