fix: 修复多数据配置的问题

This commit is contained in:
CaptainB 2024-08-12 21:53:58 +08:00 committed by 刘瑞斌
parent 6444e3f9da
commit a6cb013e9b
7 changed files with 92 additions and 12 deletions

View File

@ -25,7 +25,18 @@ spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
# quartz datasource
spring.datasource.quartz.url=${spring.datasource.url}
spring.datasource.quartz.username=${spring.datasource.username}
spring.datasource.quartz.password=${spring.datasource.password}
spring.datasource.quartz.hikari.maximum-pool-size=50
spring.datasource.quartz.hikari.minimum-idle=10
spring.datasource.quartz.hikari.idle-timeout=300000
spring.datasource.quartz.hikari.auto-commit=true
spring.datasource.quartz.hikari.pool-name=DatebookHikariCP
spring.datasource.quartz.hikari.max-lifetime=1800000
spring.datasource.quartz.hikari.connection-timeout=30000
spring.datasource.quartz.hikari.connection-test-query=SELECT 1
# 单元测试初始化权限 sql
spring.sql.init.mode=always
spring.sql.init.schema-locations=classpath*:dml/init_permission_test.sql
@ -88,4 +99,4 @@ minio.secret-key=${embedded.minio.secretKey}
logging.level.org.springframework.jdbc.core=info
logging.level.io.metersphere.sdk.mapper=info
logging.level.io.metersphere.project.mapper=info
logging.level.io.metersphere.project.mapper=info

View File

@ -25,7 +25,18 @@ spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
# quartz datasource
spring.datasource.quartz.url=${spring.datasource.url}
spring.datasource.quartz.username=${spring.datasource.username}
spring.datasource.quartz.password=${spring.datasource.password}
spring.datasource.quartz.hikari.maximum-pool-size=50
spring.datasource.quartz.hikari.minimum-idle=10
spring.datasource.quartz.hikari.idle-timeout=300000
spring.datasource.quartz.hikari.auto-commit=true
spring.datasource.quartz.hikari.pool-name=DatebookHikariCP
spring.datasource.quartz.hikari.max-lifetime=1800000
spring.datasource.quartz.hikari.connection-timeout=30000
spring.datasource.quartz.hikari.connection-test-query=SELECT 1
# 单元测试初始化权限 sql
spring.sql.init.mode=always
spring.sql.init.schema-locations=classpath*:dml/init_permission_test.sql

View File

@ -25,7 +25,18 @@ spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
# quartz datasource
spring.datasource.quartz.url=${spring.datasource.url}
spring.datasource.quartz.username=${spring.datasource.username}
spring.datasource.quartz.password=${spring.datasource.password}
spring.datasource.quartz.hikari.maximum-pool-size=50
spring.datasource.quartz.hikari.minimum-idle=10
spring.datasource.quartz.hikari.idle-timeout=300000
spring.datasource.quartz.hikari.auto-commit=true
spring.datasource.quartz.hikari.pool-name=DatebookHikariCP
spring.datasource.quartz.hikari.max-lifetime=1800000
spring.datasource.quartz.hikari.connection-timeout=30000
spring.datasource.quartz.hikari.connection-test-query=SELECT 1
#
# spring.kafka
spring.kafka.bootstrap-servers=${embedded.kafka.brokerList}
@ -84,4 +95,4 @@ minio.secret-key=${embedded.minio.secretKey}
logging.level.org.springframework.jdbc.core=info
logging.level.io.metersphere.sdk.mapper=info
logging.level.io.metersphere.functional.mapper=info
logging.level.io.metersphere.functional.mapper=info

View File

@ -25,7 +25,18 @@ spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
# quartz datasource
spring.datasource.quartz.url=${spring.datasource.url}
spring.datasource.quartz.username=${spring.datasource.username}
spring.datasource.quartz.password=${spring.datasource.password}
spring.datasource.quartz.hikari.maximum-pool-size=50
spring.datasource.quartz.hikari.minimum-idle=10
spring.datasource.quartz.hikari.idle-timeout=300000
spring.datasource.quartz.hikari.auto-commit=true
spring.datasource.quartz.hikari.pool-name=DatebookHikariCP
spring.datasource.quartz.hikari.max-lifetime=1800000
spring.datasource.quartz.hikari.connection-timeout=30000
spring.datasource.quartz.hikari.connection-test-query=SELECT 1
# 单元测试初始化权限 sql
spring.sql.init.mode=always
spring.sql.init.schema-locations=classpath*:dml/init_permission_test.sql
@ -85,4 +96,4 @@ minio.secret-key=${embedded.minio.secretKey}
logging.level.org.springframework.jdbc.core=info
logging.level.io.metersphere.sdk.mapper=info
logging.level.io.metersphere.project.mapper=info
metersphere.file.batch-download-max=600MB
metersphere.file.batch-download-max=600MB

View File

@ -7,6 +7,7 @@ import io.metersphere.system.interceptor.MybatisInterceptor;
import io.metersphere.system.interceptor.UserDesensitizationInterceptor;
import io.metersphere.system.utils.MybatisInterceptorConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
@ -58,7 +59,7 @@ public class MybatisConfig {
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource.hikari")
public DataSource dataSource(DataSourceProperties properties) {
public DataSource dataSource(@Qualifier("dataSourceProperties") DataSourceProperties properties) {
return DataSourceBuilder.create(properties.getClassLoader()).type(HikariDataSource.class)
.driverClassName(properties.determineDriverClassName())
.url(properties.determineUrl())
@ -70,7 +71,7 @@ public class MybatisConfig {
@Bean
@ConfigurationProperties(prefix = "spring.datasource.quartz.hikari")
@QuartzDataSource
public DataSource quartzDataSource(DataSourceProperties properties) {
public DataSource quartzDataSource(@Qualifier("quartzDataSourceProperties") DataSourceProperties properties) {
return DataSourceBuilder.create(properties.getClassLoader()).type(HikariDataSource.class)
.driverClassName(properties.determineDriverClassName())
.url(properties.determineUrl())
@ -79,4 +80,16 @@ public class MybatisConfig {
.build();
}
@Bean("dataSourceProperties")
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSourceProperties dataSourceProperties() {
return new DataSourceProperties();
}
@Bean("quartzDataSourceProperties")
@ConfigurationProperties(prefix = "spring.datasource.quartz")
public DataSourceProperties quartzDataSourceProperties() {
return new DataSourceProperties();
}
}

View File

@ -25,7 +25,18 @@ spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
# quartz datasource
spring.datasource.quartz.url=${spring.datasource.url}
spring.datasource.quartz.username=${spring.datasource.username}
spring.datasource.quartz.password=${spring.datasource.password}
spring.datasource.quartz.hikari.maximum-pool-size=50
spring.datasource.quartz.hikari.minimum-idle=10
spring.datasource.quartz.hikari.idle-timeout=300000
spring.datasource.quartz.hikari.auto-commit=true
spring.datasource.quartz.hikari.pool-name=DatebookHikariCP
spring.datasource.quartz.hikari.max-lifetime=1800000
spring.datasource.quartz.hikari.connection-timeout=30000
spring.datasource.quartz.hikari.connection-test-query=SELECT 1
# 单元测试初始化权限 sql
spring.sql.init.mode=always
spring.sql.init.schema-locations=classpath*:dml/init_permission_test.sql
@ -84,4 +95,4 @@ minio.secret-key=${embedded.minio.secretKey}
logging.level.org.springframework.jdbc.core=info
logging.level.io.metersphere.sdk.mapper=info
logging.level.io.metersphere.system.mapper=info
logging.level.io.metersphere.system.mapper=info

View File

@ -25,6 +25,18 @@ spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
# quartz datasource
spring.datasource.quartz.url=${spring.datasource.url}
spring.datasource.quartz.username=${spring.datasource.username}
spring.datasource.quartz.password=${spring.datasource.password}
spring.datasource.quartz.hikari.maximum-pool-size=50
spring.datasource.quartz.hikari.minimum-idle=10
spring.datasource.quartz.hikari.idle-timeout=300000
spring.datasource.quartz.hikari.auto-commit=true
spring.datasource.quartz.hikari.pool-name=DatebookHikariCP
spring.datasource.quartz.hikari.max-lifetime=1800000
spring.datasource.quartz.hikari.connection-timeout=30000
spring.datasource.quartz.hikari.connection-test-query=SELECT 1
# 单元测试初始化权限 sql
spring.sql.init.mode=always
spring.sql.init.schema-locations=classpath*:dml/init_permission_test.sql
@ -84,4 +96,4 @@ logging.level.org.springframework.jdbc.core=info
logging.level.io.metersphere.sdk.mapper=info
logging.level.io.metersphere.system.mapper=info
logging.level.io.metersphere.plan.mapper=info
metersphere.file.batch-download-max=600MB
metersphere.file.batch-download-max=600MB