mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
!78 关于 druid-spring-boot-starter 整合问题的解决
Merge pull request !78 from 王帅/main
This commit is contained in:
commit
5ab1d43731
@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Map;
|
||||
@ -33,11 +34,11 @@ import java.util.Map;
|
||||
/**
|
||||
* 多数据源的配置支持
|
||||
*/
|
||||
@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
|
||||
@ConditionalOnMybatisFlexDatasource()
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(MybatisFlexProperties.class)
|
||||
@AutoConfigureBefore({DataSourceAutoConfiguration.class})
|
||||
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
|
||||
@AutoConfigureBefore(value = DataSourceAutoConfiguration.class, name = "com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure")
|
||||
public class MultiDataSourceAutoConfiguration {
|
||||
|
||||
private final Map<String, Map<String, String>> dataSourceProperties;
|
||||
@ -55,12 +56,12 @@ public class MultiDataSourceAutoConfiguration {
|
||||
FlexDataSource flexDataSource = null;
|
||||
|
||||
if (dataSourceProperties != null && !dataSourceProperties.isEmpty()) {
|
||||
for (String key : dataSourceProperties.keySet()) {
|
||||
DataSource dataSource = new DataSourceBuilder(dataSourceProperties.get(key)).build();
|
||||
for (Map.Entry<String, Map<String, String>> entry : dataSourceProperties.entrySet()) {
|
||||
DataSource dataSource = new DataSourceBuilder(entry.getValue()).build();
|
||||
if (flexDataSource == null) {
|
||||
flexDataSource = new FlexDataSource(key, dataSource);
|
||||
flexDataSource = new FlexDataSource(entry.getKey(), dataSource);
|
||||
} else {
|
||||
flexDataSource.addDataSource(key, dataSource);
|
||||
flexDataSource.addDataSource(entry.getKey(), dataSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,15 +35,21 @@
|
||||
<version>2.0.32</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-jdbc</artifactId>-->
|
||||
<!-- <version>2.7.9</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.18</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework</groupId>-->
|
||||
<!-- <artifactId>spring-jdbc</artifactId>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-jdbc</artifactId>-->
|
||||
<!-- <version>2.7.9</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework</groupId>-->
|
||||
<!-- <artifactId>spring-jdbc</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
# DataSource Config
|
||||
#spring:
|
||||
# h2:
|
||||
# console:
|
||||
# enabled: true
|
||||
# datasource:
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/flex_test
|
||||
# username: root
|
||||
# password: 12345678
|
||||
spring:
|
||||
# h2:
|
||||
# console:
|
||||
# enabled: true
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/flex_test
|
||||
username: root
|
||||
password: 12345678
|
||||
# sql:
|
||||
# init:
|
||||
# schema-locations: classpath:schema.sql
|
||||
@ -15,11 +15,11 @@
|
||||
mybatis-flex:
|
||||
mapper-locations:
|
||||
- classpath*:/mapper/*.xml
|
||||
datasource:
|
||||
data-center:
|
||||
url: jdbc:mysql://localhost:3306/flex_test
|
||||
username: root
|
||||
password: 12345678
|
||||
# datasource:
|
||||
# data-center:
|
||||
# url: jdbc:mysql://localhost:3306/flex_test
|
||||
# username: root
|
||||
# password: 12345678
|
||||
#mybatis-flex:
|
||||
# datasource:
|
||||
# ds1:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user