mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28: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.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.util.Map;
|
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()
|
@ConditionalOnMybatisFlexDatasource()
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableConfigurationProperties(MybatisFlexProperties.class)
|
@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 {
|
public class MultiDataSourceAutoConfiguration {
|
||||||
|
|
||||||
private final Map<String, Map<String, String>> dataSourceProperties;
|
private final Map<String, Map<String, String>> dataSourceProperties;
|
||||||
@ -55,12 +56,12 @@ public class MultiDataSourceAutoConfiguration {
|
|||||||
FlexDataSource flexDataSource = null;
|
FlexDataSource flexDataSource = null;
|
||||||
|
|
||||||
if (dataSourceProperties != null && !dataSourceProperties.isEmpty()) {
|
if (dataSourceProperties != null && !dataSourceProperties.isEmpty()) {
|
||||||
for (String key : dataSourceProperties.keySet()) {
|
for (Map.Entry<String, Map<String, String>> entry : dataSourceProperties.entrySet()) {
|
||||||
DataSource dataSource = new DataSourceBuilder(dataSourceProperties.get(key)).build();
|
DataSource dataSource = new DataSourceBuilder(entry.getValue()).build();
|
||||||
if (flexDataSource == null) {
|
if (flexDataSource == null) {
|
||||||
flexDataSource = new FlexDataSource(key, dataSource);
|
flexDataSource = new FlexDataSource(entry.getKey(), dataSource);
|
||||||
} else {
|
} else {
|
||||||
flexDataSource.addDataSource(key, dataSource);
|
flexDataSource.addDataSource(entry.getKey(), dataSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,15 +35,21 @@
|
|||||||
<version>2.0.32</version>
|
<version>2.0.32</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- <dependency>-->
|
<dependency>
|
||||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
<groupId>com.alibaba</groupId>
|
||||||
<!-- <artifactId>spring-boot-starter-jdbc</artifactId>-->
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
<!-- <version>2.7.9</version>-->
|
<version>1.2.18</version>
|
||||||
<!-- </dependency>-->
|
</dependency>
|
||||||
|
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>org.springframework</groupId>-->
|
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||||
<!-- <artifactId>spring-jdbc</artifactId>-->
|
<!-- <artifactId>spring-boot-starter-jdbc</artifactId>-->
|
||||||
|
<!-- <version>2.7.9</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.springframework</groupId>-->
|
||||||
|
<!-- <artifactId>spring-jdbc</artifactId>-->
|
||||||
<!-- </dependency>-->
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
# DataSource Config
|
# DataSource Config
|
||||||
#spring:
|
spring:
|
||||||
# h2:
|
# h2:
|
||||||
# console:
|
# console:
|
||||||
# enabled: true
|
# enabled: true
|
||||||
# datasource:
|
datasource:
|
||||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
# url: jdbc:mysql://localhost:3306/flex_test
|
url: jdbc:mysql://localhost:3306/flex_test
|
||||||
# username: root
|
username: root
|
||||||
# password: 12345678
|
password: 12345678
|
||||||
# sql:
|
# sql:
|
||||||
# init:
|
# init:
|
||||||
# schema-locations: classpath:schema.sql
|
# schema-locations: classpath:schema.sql
|
||||||
@ -15,11 +15,11 @@
|
|||||||
mybatis-flex:
|
mybatis-flex:
|
||||||
mapper-locations:
|
mapper-locations:
|
||||||
- classpath*:/mapper/*.xml
|
- classpath*:/mapper/*.xml
|
||||||
datasource:
|
# datasource:
|
||||||
data-center:
|
# data-center:
|
||||||
url: jdbc:mysql://localhost:3306/flex_test
|
# url: jdbc:mysql://localhost:3306/flex_test
|
||||||
username: root
|
# username: root
|
||||||
password: 12345678
|
# password: 12345678
|
||||||
#mybatis-flex:
|
#mybatis-flex:
|
||||||
# datasource:
|
# datasource:
|
||||||
# ds1:
|
# ds1:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user