多数据源修复

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> <oshi.version>6.5.0</oshi.version>
<velocity.version>2.3</velocity.version> <velocity.version>2.3</velocity.version>
<mybatis-plus.version>3.4.2</mybatis-plus.version> <mybatis-plus.version>3.4.2</mybatis-plus.version>
<taos.version>3.3.3</taos.version>
</properties> </properties>
<dependencies> <dependencies>
@ -250,6 +251,13 @@
</exclusions> </exclusions>
</dependency> </dependency>
<!-- taos -->
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>${taos.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <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.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; 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.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template; import org.apache.velocity.Template;
@ -73,6 +76,7 @@ public class GenTableServiceImpl implements IGenTableService
* @return 业务集合 * @return 业务集合
*/ */
@Override @Override
@DataSource(value = DataSourceType.SLAVE)
public List<GenTable> selectGenTableList(GenTable genTable) public List<GenTable> selectGenTableList(GenTable genTable)
{ {
return genTableMapper.selectGenTableList(genTable); return genTableMapper.selectGenTableList(genTable);

View File

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