Commit 0f1a81d8 by qiuweili123

1.调整组件结构

2.增加默认的数据源为druid
3.删除数据源无关jar
parent 37bd44fa
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-datasource</artifactId> <artifactId>matrix-datasource</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -28,15 +28,6 @@ ...@@ -28,15 +28,6 @@
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>app-security-algo</artifactId> <artifactId>app-security-algo</artifactId>
</dependency> </dependency>
<!--所依赖的数据源-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
...@@ -57,11 +48,6 @@ ...@@ -57,11 +48,6 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
package com.secoo.mall.datasource.bean; package com.secoo.mall.datasource.bean;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig; import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import com.secoo.mall.datasource.constant.DataSourceTypeEnum; import com.secoo.mall.datasource.factory.DataSourceFactory;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.reflect.MethodUtils; import org.apache.commons.lang3.reflect.MethodUtils;
import javax.annotation.Resource;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
...@@ -23,8 +25,8 @@ public class MatrixDataSource implements DataSource, Closeable { ...@@ -23,8 +25,8 @@ public class MatrixDataSource implements DataSource, Closeable {
} }
public MatrixDataSource(DataSourceTypeEnum dataSourceTypeEnum, MatrixDataSourceConfig config) { public MatrixDataSource(DataSourceFactory dataSourceFactory,MatrixDataSourceConfig config) {
dataSource = dataSourceTypeEnum.getDataSourceFactory().createDataSouce(config); dataSource = dataSourceFactory.createDataSouce(config);
} }
......
package com.secoo.mall.datasource.config; package com.secoo.mall.datasource.config;
import com.secoo.mall.datasource.factory.DataSourceFactory;
import lombok.Data; import lombok.Data;
@Data @Data
......
package com.secoo.mall.datasource.constant;
import com.secoo.mall.datasource.factory.DataSourceFactory;
import com.secoo.mall.datasource.factory.DruidDataSourceFactory;
import com.secoo.mall.datasource.factory.HikariDataSourceFactory;
public enum DataSourceTypeEnum {
DRUID("druid", new DruidDataSourceFactory()), HIKARI("hikari", new HikariDataSourceFactory());
private String name;
private DataSourceFactory dataSourceFactory;
DataSourceTypeEnum(String name, DataSourceFactory dataSourceFactory) {
this.name = name;
this.dataSourceFactory = dataSourceFactory;
}
public String getName() {
return name;
}
public DataSourceFactory getDataSourceFactory() {
return dataSourceFactory;
}
public static DataSourceTypeEnum getByName(String name) {
for (DataSourceTypeEnum typeEnum : DataSourceTypeEnum.values()) {
if (typeEnum.getName().equals(name)) {
return typeEnum;
}
}
return null;
}
}
...@@ -4,7 +4,8 @@ import com.secoo.mall.common.core.errorcode.ErrorCode; ...@@ -4,7 +4,8 @@ import com.secoo.mall.common.core.errorcode.ErrorCode;
public interface DataSourceError { public interface DataSourceError {
ErrorCode APOLLO_CONFIG_NOT_EXIST = new ErrorCode(1, "appollo config not exits"); ErrorCode APOLLO_CONFIG_NOT_EXIST = new ErrorCode(1, "appollo config not exits");
ErrorCode PRIVATE_KEY_NOT_EXIST = new ErrorCode(2, "http get privatekey fail"); ErrorCode SOUCE_FACTORY_NOT_EXIST = new ErrorCode(2, "data source factory bean not config");
ErrorCode APP_ID_NOT_EXIST = new ErrorCode(3, "please config -Dappp.id"); ErrorCode APP_ID_NOT_EXIST = new ErrorCode(3, "please config -Dappp.id");
ErrorCode DATA_SOURCE_NOT_EXIST = new ErrorCode(4, "could not find a datasource named %s"); ErrorCode DATA_SOURCE_NOT_EXIST = new ErrorCode(4, "could not find a datasource named %s");
} }
...@@ -4,16 +4,15 @@ import com.secoo.mall.datasource.config.MatrixDataSourceConfig; ...@@ -4,16 +4,15 @@ import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import javax.sql.DataSource; import javax.sql.DataSource;
public abstract class AbsDataSourceFactory<T> implements DataSourceFactory<T> { public abstract class AbsDataSourceFactory<T extends DataSource, CONFIG extends MatrixDataSourceConfig> implements DataSourceFactory<T, CONFIG> {
@Override public T createDataSouce(CONFIG config) {
public <T extends DataSource> T createDataSouce(MatrixDataSourceConfig config) {
return convertAndCreate(config); return convertAndCreate(config);
} }
protected abstract <T extends DataSource> T convertAndCreate(MatrixDataSourceConfig config); protected abstract <T extends DataSource> T convertAndCreate(CONFIG config);
} }
......
...@@ -4,8 +4,8 @@ import com.secoo.mall.datasource.config.MatrixDataSourceConfig; ...@@ -4,8 +4,8 @@ import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import javax.sql.DataSource; import javax.sql.DataSource;
public interface DataSourceFactory<T> { public interface DataSourceFactory<T extends DataSource,CONFIG extends MatrixDataSourceConfig> {
<T extends DataSource> T createDataSouce(MatrixDataSourceConfig config); T createDataSouce( CONFIG config);
} }
package com.secoo.mall.datasource.factory;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
public class HikariDataSourceFactory extends AbsDataSourceFactory<HikariDataSource> {
@Override
protected HikariDataSource convertAndCreate(MatrixDataSourceConfig config) {
//基础配置
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(config.getUrl());
hikariConfig.setPoolName(config.getName());
hikariConfig.setUsername(config.getUsername());
hikariConfig.setPassword(config.getPassword());
//连接相关配置
hikariConfig.setMinimumIdle(config.getMinimumIdle());
hikariConfig.setMinimumIdle(config.getMinimumIdle());
hikariConfig.setMaximumPoolSize(config.getMaximumPoolSize());
hikariConfig.setIdleTimeout(config.getIdleTimeout());
hikariConfig.setMaxLifetime(config.getMaxLifetime());
hikariConfig.setConnectionTimeout(config.getConnectionTimeout());
return new HikariDataSource(hikariConfig);
}
}
package com.secoo.mall.datasource.properties; package com.secoo.mall.datasource.properties;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig; import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import com.secoo.mall.datasource.constant.DataSourceTypeEnum;
import lombok.Data; import lombok.Data;
@Data @Data
public class MatrixDataSourceProperties extends MatrixDataSourceConfig { public class MatrixDataSourceProperties extends MatrixDataSourceConfig {
public static final String PREFIX = "spring.datasource.matrix"; public static final String PREFIX = "spring.datasource.matrix";
public static final DataSourceTypeEnum DEFAULT_DATASOURCE_TYPE = DataSourceTypeEnum.HIKARI;
public MatrixDataSourceProperties() { public MatrixDataSourceProperties() {
} }
}
/**
* SourceType DRUID or HIKARI.
* Default value HIKARI.
*/
private DataSourceTypeEnum type = DEFAULT_DATASOURCE_TYPE;
public void setType(String type) {
this.type = DataSourceTypeEnum.getByName(type);
}
}
...@@ -2,26 +2,37 @@ package com.secoo.mall.datasource.provider; ...@@ -2,26 +2,37 @@ package com.secoo.mall.datasource.provider;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.secoo.mall.app.security.encryptor.Encryptor; import com.secoo.mall.app.security.encryptor.Encryptor;
import com.secoo.mall.datasource.bean.MatrixDataSource;
import com.secoo.mall.datasource.config.DataSourceConfig; import com.secoo.mall.datasource.config.DataSourceConfig;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import com.secoo.mall.datasource.constant.DataSourceConstant; import com.secoo.mall.datasource.constant.DataSourceConstant;
import com.secoo.mall.datasource.factory.DataSourceFactory;
import com.secoo.mall.datasource.factory.EncryptorFactory; import com.secoo.mall.datasource.factory.EncryptorFactory;
import com.secoo.mall.datasource.properties.MatrixDataSourceProperties;
import javax.annotation.Resource;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.lang.reflect.ParameterizedType;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public abstract class AbsDataSourceProvider<T extends MatrixDataSourceProperties> implements DataSourceProvider { public abstract class AbsDataSourceProvider<T extends MatrixDataSourceConfig> implements DataSourceProvider {
private Encryptor<String> encryptor = EncryptorFactory.getInstance().getEncryptor(); private Encryptor<String> encryptor = EncryptorFactory.getInstance().getEncryptor();
@Resource
private DataSourceFactory dataSourceFactory;
private Class<T> entryClass;
public AbsDataSourceProvider() {
entryClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
@Override @Override
public Map<String, DataSource> loadDataSources() { public Map<String, DataSource> loadDataSources() {
List<T> list = getDataSourceProperties(); List<T> list = getDataSourceProperties();
Map<String, DataSource> dataSourceMap = Maps.newHashMapWithExpectedSize(list.size()); Map<String, DataSource> dataSourceMap = Maps.newHashMapWithExpectedSize(list.size());
for (T properties : list) { for (T properties : list) {
DataSource dataSource = new MatrixDataSource(properties.getType(), properties); DataSource dataSource = dataSourceFactory.createDataSouce(properties);
//取得原数据源名称 //取得原数据源名称
String dsName = properties.getName().replace(DataSourceConfig.POOL_NAME_PRIFIX, ""); String dsName = properties.getName().replace(DataSourceConfig.POOL_NAME_PRIFIX, "");
dataSourceMap.put(dsName, dataSource); dataSourceMap.put(dsName, dataSource);
...@@ -40,6 +51,10 @@ public abstract class AbsDataSourceProvider<T extends MatrixDataSourceProperties ...@@ -40,6 +51,10 @@ public abstract class AbsDataSourceProvider<T extends MatrixDataSourceProperties
} }
public Class<T> getEntryClass() {
return entryClass;
}
protected abstract List<T> getDataSourceProperties(); protected abstract List<T> getDataSourceProperties();
......
...@@ -6,6 +6,7 @@ import com.google.common.collect.Lists; ...@@ -6,6 +6,7 @@ import com.google.common.collect.Lists;
import com.secoo.mall.common.core.exception.BusinessException; import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.common.util.colletion.CollectionUtil; import com.secoo.mall.common.util.colletion.CollectionUtil;
import com.secoo.mall.common.util.string.StringUtil; import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import com.secoo.mall.datasource.constant.DataSourceConstant; import com.secoo.mall.datasource.constant.DataSourceConstant;
import com.secoo.mall.datasource.errorcode.DataSourceError; import com.secoo.mall.datasource.errorcode.DataSourceError;
import com.secoo.mall.datasource.properties.MatrixDataSourceProperties; import com.secoo.mall.datasource.properties.MatrixDataSourceProperties;
...@@ -13,6 +14,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -13,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.reflect.MethodUtils; import org.apache.commons.lang3.reflect.MethodUtils;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -23,8 +25,10 @@ import java.util.stream.Collectors; ...@@ -23,8 +25,10 @@ import java.util.stream.Collectors;
* 从Apollo配置中心进行加载 * 从Apollo配置中心进行加载
*/ */
@Slf4j @Slf4j
public class ApolloDataSourceProvider extends AbsDataSourceProvider<MatrixDataSourceProperties> { public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends AbsDataSourceProvider<T> {
/*
*/
/** /**
* 从appollo加载配置信息 * 从appollo加载配置信息
...@@ -32,10 +36,12 @@ public class ApolloDataSourceProvider extends AbsDataSourceProvider<MatrixDataSo ...@@ -32,10 +36,12 @@ public class ApolloDataSourceProvider extends AbsDataSourceProvider<MatrixDataSo
* @return * @return
*/ */
@Override @Override
protected List<MatrixDataSourceProperties> getDataSourceProperties() { protected List<T> getDataSourceProperties() {
Config appConfig = ConfigService.getConfig(DataSourceConstant.DB_NAMESPACE); Config appConfig = ConfigService.getConfig(DataSourceConstant.DB_NAMESPACE);
Set<String> propertyNames = appConfig.getPropertyNames(); Set<String> propertyNames = appConfig.getPropertyNames();
List<MatrixDataSourceProperties> list = Lists.newArrayList(); List<T> list = Lists.newArrayList();
Map<String, DataSource> dataSourceMap = new HashMap<>(); Map<String, DataSource> dataSourceMap = new HashMap<>();
if (CollectionUtil.isEmpty(propertyNames)) { if (CollectionUtil.isEmpty(propertyNames)) {
throw new BusinessException(DataSourceError.APOLLO_CONFIG_NOT_EXIST); throw new BusinessException(DataSourceError.APOLLO_CONFIG_NOT_EXIST);
...@@ -47,8 +53,7 @@ public class ApolloDataSourceProvider extends AbsDataSourceProvider<MatrixDataSo ...@@ -47,8 +53,7 @@ public class ApolloDataSourceProvider extends AbsDataSourceProvider<MatrixDataSo
try { try {
for (Map.Entry<String, List<String>> entry : propertyMap.entrySet()) { for (Map.Entry<String, List<String>> entry : propertyMap.entrySet()) {
String dsName = entry.getKey(); String dsName = entry.getKey();
MatrixDataSourceProperties matrixDataSourceProperties = new MatrixDataSourceProperties(); T matrixDataSourceProperties = getEntryClass().newInstance();
matrixDataSourceProperties.setName(dsName); matrixDataSourceProperties.setName(dsName);
for (String property : entry.getValue()) { for (String property : entry.getValue()) {
String propertyFullPath = MatrixDataSourceProperties.PREFIX + property; String propertyFullPath = MatrixDataSourceProperties.PREFIX + property;
......
package com.secoo.mall.mybatis.datasouce;
import com.secoo.mall.datasource.bean.MatrixDataSource;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import com.secoo.mall.datasource.constant.DataSourceTypeEnum;
import org.junit.Test;
public class DataSourceTest {
@Test
public void testCreateDataSource() {
MatrixDataSourceConfig config = new MatrixDataSourceConfig();
config.setName("01");
// config.setType(DataSourceType.HIKARI);
config.setUrl("jdbc:mysql://127.0.0.1:3306/appmsdb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false");
config.setPassword("mysql");
config.setUsername("root");
MatrixDataSource dataSource = new MatrixDataSource(DataSourceTypeEnum.HIKARI, config);
System.out.println(dataSource);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-datasource</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.10.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-datasource-druid</artifactId>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-core</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
...@@ -2,14 +2,19 @@ package com.secoo.mall.datasource.factory; ...@@ -2,14 +2,19 @@ package com.secoo.mall.datasource.factory;
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidDataSource;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig; import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import com.secoo.mall.datasource.properties.MatrixDruidDataSourceProperties;
import lombok.extern.slf4j.Slf4j;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Properties; import java.util.Properties;
public class DruidDataSourceFactory extends AbsDataSourceFactory<DruidDataSource> { @Slf4j
public class DruidDataSourceFactory extends AbsDataSourceFactory<DruidDataSource, MatrixDruidDataSourceProperties> {
private final String duridPreFix = "druid."; private final String duridPreFix = "druid.";
@Override @Override
protected DruidDataSource convertAndCreate(MatrixDataSourceConfig config) { protected DruidDataSource convertAndCreate(MatrixDruidDataSourceProperties config) {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(duridPreFix + "name", config.getName()); properties.setProperty(duridPreFix + "name", config.getName());
...@@ -25,7 +30,14 @@ public class DruidDataSourceFactory extends AbsDataSourceFactory<DruidDataSource ...@@ -25,7 +30,14 @@ public class DruidDataSourceFactory extends AbsDataSourceFactory<DruidDataSource
DruidDataSource dataSource = new DruidDataSource(); DruidDataSource dataSource = new DruidDataSource();
dataSource.configFromPropety(properties); dataSource.configFromPropety(properties);
try {
dataSource.init();
} catch (SQLException e) {
log.error("sql error:", e);
}
return dataSource; return dataSource;
} }
} }
package com.secoo.mall.datasource.properties;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import lombok.Data;
@Data
public class MatrixDruidDataSourceProperties extends MatrixDataSourceProperties {
public static final String PREFIX = MatrixDataSourceProperties.PREFIX+".druid";
}
package com.secoo.mall.datasource.provider;
import com.secoo.mall.datasource.properties.MatrixDruidDataSourceProperties;
public class ApolloDruidDataSourceProvider extends ApolloDataSourceProvider<MatrixDruidDataSourceProperties> {
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -13,23 +13,20 @@ ...@@ -13,23 +13,20 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>matrix-datasource-core</module> <module>matrix-datasource-core</module>
<module>matrix-datasource-druid</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>HikariCP</artifactId> <artifactId>matrix-datasource-core</artifactId>
<version>3.2.0</version> <version>1.1.10.RELEASE</version>
<scope>provided</scope>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>druid</artifactId> <artifactId>druid</artifactId>
<version>1.1.20</version> <version>1.1.20</version>
<scope>provided</scope>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-mybatis</artifactId> <artifactId>matrix-mybatis</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-core</artifactId> <artifactId>matrix-datasource-druid</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-mybatis</artifactId> <artifactId>matrix-mybatis</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
package com.secoo.mall.mybatis.spring.boot.autoconfigure; package com.secoo.mall.mybatis.spring.boot.autoconfigure;
import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
import com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration; import com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration;
import com.secoo.mall.datasource.bean.MatrixDataSource; import com.secoo.mall.datasource.bean.MatrixDataSource;
import com.secoo.mall.datasource.bean.MatrixDynamicDataSource; import com.secoo.mall.datasource.bean.MatrixDynamicDataSource;
import com.secoo.mall.datasource.provider.ApolloDataSourceProvider; import com.secoo.mall.datasource.factory.DataSourceFactory;
import com.secoo.mall.datasource.factory.DruidDataSourceFactory;
import com.secoo.mall.datasource.provider.ApolloDruidDataSourceProvider;
import com.secoo.mall.datasource.provider.DataSourceProvider; import com.secoo.mall.datasource.provider.DataSourceProvider;
import com.secoo.mall.datasource.util.SysUtil; import com.secoo.mall.datasource.util.SysUtil;
import com.secoo.mall.mybatis.bean.MatrixMybatisSqlSessionFactoryBean; import com.secoo.mall.mybatis.bean.MatrixMybatisSqlSessionFactoryBean;
...@@ -19,9 +22,11 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore; ...@@ -19,9 +22,11 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 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.autoconfigure.jdbc.DataSourceProperties;
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 org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource; import javax.sql.DataSource;
...@@ -42,11 +47,12 @@ public class MatrixMybatisAutoConfiguration { ...@@ -42,11 +47,12 @@ public class MatrixMybatisAutoConfiguration {
@Value("${config.app.security.accessToken}") @Value("${config.app.security.accessToken}")
private String acccessToken; private String acccessToken;
@Bean @Bean
@ConditionalOnMissingBean(DataSourceProvider.class) @ConditionalOnMissingBean(DataSourceProvider.class)
public DataSourceProvider dataSourceProvider() { public DataSourceProvider dataSourceProvider() {
SysUtil.setProperty("accessToken", acccessToken); SysUtil.setProperty("accessToken", acccessToken);
return new ApolloDataSourceProvider(); return new ApolloDruidDataSourceProvider();
} }
/** /**
...@@ -61,6 +67,13 @@ public class MatrixMybatisAutoConfiguration { ...@@ -61,6 +67,13 @@ public class MatrixMybatisAutoConfiguration {
} }
@Bean @Bean
@ConditionalOnMissingBean(DataSourceFactory.class)
public DataSourceFactory dataSourceFactory() {
return new DruidDataSourceFactory();
}
@Bean
@ConditionalOnMissingBean(SqlSessionFactory.class) @ConditionalOnMissingBean(SqlSessionFactory.class)
public SqlSessionFactory sqlSessionFactory(DataSource dataSource, MatrixMybatisConfig matrixMybatisConfig, MatrixMybatisGlobalConfig matrixMybatisGlobalConfig) throws Exception { public SqlSessionFactory sqlSessionFactory(DataSource dataSource, MatrixMybatisConfig matrixMybatisConfig, MatrixMybatisGlobalConfig matrixMybatisGlobalConfig) throws Exception {
MatrixMybatisSqlSessionFactoryBean sqlSessionFactory = new MatrixMybatisSqlSessionFactoryBean(matrixMybatisConfig, matrixMybatisGlobalConfig); MatrixMybatisSqlSessionFactoryBean sqlSessionFactory = new MatrixMybatisSqlSessionFactoryBean(matrixMybatisConfig, matrixMybatisGlobalConfig);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -25,22 +25,28 @@ ...@@ -25,22 +25,28 @@
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-core</artifactId> <artifactId>matrix-mybatis-core</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-starter</artifactId> <artifactId>matrix-mybatis-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId> <artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version> <version>${mybatis-plus.version}</version>
<exclusions>
<exclusion>
<artifactId>HikariCP</artifactId>
<groupId>com.zaxxer</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-core</artifactId> <artifactId>matrix-datasource-druid</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>common-core</module> <module>common-core</module>
<module>common-util</module> <module>common-util</module>
<module>logger-starter</module>
<module>redis-starter</module> <module>redis-starter</module>
<module>matrix-mybatis</module> <module>matrix-mybatis</module>
<module>mongodb-starter</module> <module>mongodb-starter</module>
...@@ -22,7 +23,6 @@ ...@@ -22,7 +23,6 @@
<module>monitor-starter</module> <module>monitor-starter</module>
<module>config-starter</module> <module>config-starter</module>
<module>protocol-starter</module> <module>protocol-starter</module>
<module>logger-starter</module>
<module>matrix-datasource</module> <module>matrix-datasource</module>
</modules> </modules>
...@@ -48,62 +48,62 @@ ...@@ -48,62 +48,62 @@
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>logger-starter</artifactId> <artifactId>logger-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>monitor-starter</artifactId> <artifactId>monitor-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>common-core</artifactId> <artifactId>common-core</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>config-starter</artifactId> <artifactId>config-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>common-util</artifactId> <artifactId>common-util</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>redis-starter</artifactId> <artifactId>redis-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-starter</artifactId> <artifactId>matrix-mybatis-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>mongodb-starter</artifactId> <artifactId>mongodb-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>elasticsearch-starter</artifactId> <artifactId>elasticsearch-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>protocol-starter</artifactId> <artifactId>protocol-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>rocketmq-starter</artifactId> <artifactId>rocketmq-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>openfeign-starter</artifactId> <artifactId>openfeign-starter</artifactId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.1.9.RELEASE</version> <version>1.1.10.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment