From 62a839d7b36dfc82a3326bfa308a93de2e29b3bf Mon Sep 17 00:00:00 2001 From: CaptainB Date: Mon, 12 Aug 2024 19:15:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=A4=9A=E6=95=B0=E6=8D=AE=E6=BA=90=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../autoconfigure/CommonsDatabaseConfig.java | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/CommonsDatabaseConfig.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/CommonsDatabaseConfig.java index 868cca8631..eb2962cf13 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/CommonsDatabaseConfig.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/CommonsDatabaseConfig.java @@ -11,6 +11,7 @@ import io.metersphere.commons.utils.MybatisInterceptorConfig; import io.metersphere.interceptor.MybatisInterceptor; import io.metersphere.interceptor.UserDesensitizationInterceptor; import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; @@ -63,12 +64,12 @@ public class CommonsDatabaseConfig { @Bean @Primary @ConfigurationProperties(prefix = "spring.datasource.hikari") - public DataSource dataSource(DataSourceProperties properties) { - return DataSourceBuilder.create(properties.getClassLoader()).type(HikariDataSource.class) - .driverClassName(properties.determineDriverClassName()) - .url(properties.determineUrl()) - .username(properties.determineUsername()) - .password(properties.determinePassword()) + public DataSource dataSource(@Qualifier("dataSourceProperties") DataSourceProperties dataSourceProperties) { + return DataSourceBuilder.create(dataSourceProperties.getClassLoader()).type(HikariDataSource.class) + .driverClassName(dataSourceProperties.determineDriverClassName()) + .url(dataSourceProperties.determineUrl()) + .username(dataSourceProperties.determineUsername()) + .password(dataSourceProperties.determinePassword()) .build(); } @@ -76,13 +77,25 @@ public class CommonsDatabaseConfig { @ConfigurationProperties(prefix = "spring.datasource.quartz.hikari") @QuartzDataSource @ConditionalOnProperty(prefix = "quartz", value = "enabled", havingValue = "true") - public DataSource quartzDataSource(DataSourceProperties properties) { - return DataSourceBuilder.create(properties.getClassLoader()).type(HikariDataSource.class) - .driverClassName(properties.determineDriverClassName()) - .url(properties.determineUrl()) - .username(properties.determineUsername()) - .password(properties.determinePassword()) + public DataSource quartzDataSource(@Qualifier("quartzDataSourceProperties") DataSourceProperties quartzDataSourceProperties) { + return DataSourceBuilder.create(quartzDataSourceProperties.getClassLoader()).type(HikariDataSource.class) + .driverClassName(quartzDataSourceProperties.determineDriverClassName()) + .url(quartzDataSourceProperties.determineUrl()) + .username(quartzDataSourceProperties.determineUsername()) + .password(quartzDataSourceProperties.determinePassword()) .build(); } -} \ No newline at end of file + @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(); + } +}