多数据源修复

This commit is contained in:
hyy 2024-11-04 15:21:31 +08:00
parent 3d313b5695
commit 6a0815b2b5
4 changed files with 55 additions and 11 deletions

View File

@ -37,6 +37,7 @@
<oshi.version>6.5.0</oshi.version>
<velocity.version>2.3</velocity.version>
<mybatis-plus.version>3.4.2</mybatis-plus.version>
<taos.version>3.3.3</taos.version>
</properties>
<dependencies>
@ -250,6 +251,13 @@
</exclusions>
</dependency>
<!-- taos -->
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>${taos.version}</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,32 @@
package com.jg.framework.config;
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 javax.sql.DataSource;
/**
* TransactionConfig
*
* @author huangge1199
* @since 2024/10/11 13:34:56
*/
@Configuration
@EnableTransactionManagement
public class TransactionConfig {
@Bean
public PlatformTransactionManager mysqlTransactionManager(DataSource mysqlDataSource) {
return new DataSourceTransactionManager(mysqlDataSource);
}
@Bean
public PlatformTransactionManager tdengineTransactionManager(DataSource tdengineDataSource) {
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(tdengineDataSource);
transactionManager.setRollbackOnCommitFailure(false); // 禁用自动回滚
return transactionManager;
}
}

View File

@ -11,6 +11,9 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import com.jg.framework.aspectj.lang.annotation.DataSource;
import com.jg.framework.aspectj.lang.enums.DataSourceType;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
@ -73,6 +76,7 @@ public class GenTableServiceImpl implements IGenTableService
* @return 业务集合
*/
@Override
@DataSource(value = DataSourceType.SLAVE)
public List<GenTable> selectGenTableList(GenTable genTable)
{
return genTableMapper.selectGenTableList(genTable);

View File

@ -2,20 +2,20 @@
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
druid:
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/jgwebsite?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
# 从库数据源
slave:
# 从数据源开关/默认关闭
enabled: false
url:
username:
password:
enabled: true
url: jdbc:TAOS://localhost:6030/ruoyi
username: root
password: taosdata
driver-class-name: com.taosdata.jdbc.TSDBDriver
# 初始连接数
initialSize: 5
# 最小连接池数量
@ -35,7 +35,7 @@ spring:
# 配置一个连接在池中最大生存的时间,单位是毫秒
maxEvictableIdleTimeMillis: 900000
# 配置检测连接是否有效
validationQuery: SELECT 1 FROM DUAL
validationQuery: SELECT 1
testWhileIdle: true
testOnBorrow: false
testOnReturn: false