Skip to content

Commit

Permalink
Merge pull request #38 from hengboy/2.3.x
Browse files Browse the repository at this point in the history
Adapt "minbox-datasource-switch" component
  • Loading branch information
hengboy authored Jul 21, 2020
2 parents c955c17 + 95b6206 commit 4aad8d2
Show file tree
Hide file tree
Showing 23 changed files with 43 additions and 715 deletions.
6 changes: 6 additions & 0 deletions api-boot-project/api-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@
<artifactId>minbox-resource-load</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.minbox.framework</groupId>
<artifactId>minbox-datasource-switch</artifactId>
<optional>true</optional>
</dependency>


<!--Others-->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.minbox.framework.api.boot.autoconfigure.datasource;

import org.minbox.framework.api.boot.datasource.ApiBootDataSource;
import org.minbox.framework.api.boot.datasource.ApiBootDataSourceFactoryBean;
import org.minbox.framework.api.boot.datasource.aop.advistor.ApiBootDataSourceSwitchAdvisor;
import org.minbox.framework.api.boot.datasource.aop.interceptor.ApiBootDataSourceSwitchAnnotationInterceptor;
import org.minbox.framework.api.boot.datasource.config.DataSourceConfig;
import org.minbox.framework.api.boot.datasource.config.DataSourceDruidConfig;
import org.minbox.framework.api.boot.datasource.routing.ApiBootRoutingDataSource;
import org.minbox.framework.api.boot.datasource.support.ApiBootDruidDataSource;
import org.minbox.framework.api.boot.datasource.support.ApiBootHikariDataSource;
import com.alibaba.druid.pool.DruidDataSource;
import org.minbox.framework.datasource.DataSourceFactoryBean;
import org.minbox.framework.datasource.MinBoxDataSource;
import org.minbox.framework.datasource.aop.advistor.DataSourceSwitchAdvisor;
import org.minbox.framework.datasource.aop.interceptor.DataSourceSwitchAnnotationInterceptor;
import org.minbox.framework.datasource.config.DataSourceConfig;
import org.minbox.framework.datasource.config.DataSourceDruidConfig;
import org.minbox.framework.datasource.routing.ApiBootRoutingDataSource;
import org.minbox.framework.datasource.support.MinBoxDruidDataSource;
import org.minbox.framework.datasource.support.MinBoxHikariDataSource;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -30,7 +31,7 @@
* @author 恒宇少年
*/
@Configuration
@ConditionalOnClass({ApiBootDataSource.class, AbstractRoutingDataSource.class})
@ConditionalOnClass({MinBoxDataSource.class, AbstractRoutingDataSource.class})
@EnableConfigurationProperties(ApiBootDataSourceSwitchProperties.class)
@AutoConfigureBefore(DataSourceAutoConfiguration.class)
public class ApiBootDataSourceSwitchAutoConfiguration {
Expand All @@ -51,21 +52,21 @@ public ApiBootDataSourceSwitchAutoConfiguration(ApiBootDataSourceSwitchPropertie
*/
@Bean
@ConditionalOnMissingBean
public ApiBootDataSourceFactoryBean apiBootDataSourceFactoryBean() {
return new ApiBootDataSourceFactoryBean();
public DataSourceFactoryBean dataSourceFactoryBean() {
return new DataSourceFactoryBean();
}

/**
* ApiBoot Routing DataSource
* switch use datasource
* {@link DataSource}
*
* @param apiBootDataSourceFactoryBean ApiBoot DataSource FactoryBean
* @param dataSourceFactoryBean ApiBoot DataSource FactoryBean
* @return DataSource
*/
@Bean
@ConditionalOnMissingBean
public DataSource dataSource(ApiBootDataSourceFactoryBean apiBootDataSourceFactoryBean) {
public DataSource dataSource(DataSourceFactoryBean dataSourceFactoryBean) {
List<DataSourceConfig> dataSourceConfigList = new LinkedList();
Map<String, DataSourceConfig> dataSourceConfigMap = new HashMap(1);

Expand All @@ -80,13 +81,13 @@ public DataSource dataSource(ApiBootDataSourceFactoryBean apiBootDataSourceFacto
// set data source pool name
dataSourceConfig.setPoolName(poolName);
// datasource type
dataSourceConfig.setDataSourceType(dataSourceConfig instanceof DataSourceDruidConfig ? ApiBootDruidDataSource.class : ApiBootHikariDataSource.class);
dataSourceConfig.setDataSourceType(dataSourceConfig instanceof DataSourceDruidConfig ? MinBoxDruidDataSource.class : MinBoxHikariDataSource.class);

// after convert add to data source list
dataSourceConfigList.add(dataSourceConfig);
});

return new ApiBootRoutingDataSource(apiBootDataSourceFactoryBean, apiBootDataSourceSwitchProperties.getPrimary(), dataSourceConfigList);
return new ApiBootRoutingDataSource(dataSourceFactoryBean, apiBootDataSourceSwitchProperties.getPrimary(), dataSourceConfigList);
}

/**
Expand All @@ -96,21 +97,21 @@ public DataSource dataSource(ApiBootDataSourceFactoryBean apiBootDataSourceFacto
*/
@Bean
@ConditionalOnMissingBean
public ApiBootDataSourceSwitchAnnotationInterceptor apiBootDataSourceSwitchAnnotationInterceptor() {
return new ApiBootDataSourceSwitchAnnotationInterceptor();
public DataSourceSwitchAnnotationInterceptor dataSourceSwitchAnnotationInterceptor() {
return new DataSourceSwitchAnnotationInterceptor();
}

/**
* ApiBoot DataSource Switch Advisor
* Used to get @DataSourceSwitch annotation define
*
* @param apiBootDataSourceSwitchAnnotationInterceptor ApiBoot DataSource Annotation Interceptor
* @param dataSourceSwitchAnnotationInterceptor ApiBoot DataSource Annotation Interceptor
* @return ApiBootDataSourceSwitchAdvisor
*/
@Bean
@ConditionalOnMissingBean
public ApiBootDataSourceSwitchAdvisor apiBootDataSourceSwitchAdvisor(ApiBootDataSourceSwitchAnnotationInterceptor apiBootDataSourceSwitchAnnotationInterceptor) {
return new ApiBootDataSourceSwitchAdvisor(apiBootDataSourceSwitchAnnotationInterceptor);
public DataSourceSwitchAdvisor apiBootDataSourceSwitchAdvisor(DataSourceSwitchAnnotationInterceptor dataSourceSwitchAnnotationInterceptor) {
return new DataSourceSwitchAdvisor(dataSourceSwitchAnnotationInterceptor);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.minbox.framework.api.boot.autoconfigure.datasource;

import lombok.Data;
import org.minbox.framework.api.boot.datasource.config.DataSourceDruidConfig;
import org.minbox.framework.api.boot.datasource.config.DataSourceHikariConfig;
import org.minbox.framework.datasource.config.DataSourceDruidConfig;
import org.minbox.framework.datasource.config.DataSourceHikariConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

Expand Down
6 changes: 6 additions & 0 deletions api-boot-project/api-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<minbox-logging.version>1.0.5.RELEASE</minbox-logging.version>
<minbox-ratelimiter.version>1.0.0.RELEASE</minbox-ratelimiter.version>
<minbox-resource-load.version>1.0.0.RELEASE</minbox-resource-load.version>
<minbox-datasource-switch.version>1.0.0.RELEASE</minbox-datasource-switch.version>
<minbox-mongo-client-settings.version>1.0.0.RELEASE</minbox-mongo-client-settings.version>
<code.builder.core.version>1.0.5.RELEASE</code.builder.core.version>
<mybatis-enhance.version>1.1.3.RELEASE</mybatis-enhance.version>
Expand Down Expand Up @@ -176,6 +177,11 @@
<artifactId>minbox-resource-load</artifactId>
<version>${minbox-resource-load.version}</version>
</dependency>
<dependency>
<groupId>org.minbox.framework</groupId>
<artifactId>minbox-datasource-switch</artifactId>
<version>${minbox-datasource-switch.version}</version>
</dependency>


<!--ApiBoot Dependencies-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@
<tag>HEAD</tag>
</scm>
<dependencies>
<!--ApiBoot Starter-->
<dependency>
<groupId>org.minbox.framework</groupId>
<artifactId>api-boot-starter</artifactId>
</dependency>
<!--SpringBoot Jdbc-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--SpringBoot Aop-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
Expand All @@ -46,5 +43,9 @@
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
</dependency>
<dependency>
<groupId>org.minbox.framework</groupId>
<artifactId>minbox-datasource-switch</artifactId>
</dependency>
</dependencies>
</project>
10 changes: 0 additions & 10 deletions api-boot-project/api-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4aad8d2

Please sign in to comment.