Commit d8e55826 by 李秋伟

Merge branch 'feature_protocol' into 'master'

Feature protocol

See merge request mall/arch/matrix!43
parents 2a9ba63c 4f339837
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,13 +5,17 @@ import com.secoo.mall.common.core.errorcode.CommonErrorCode;
import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.common.core.exception.SystemInternalException;
import com.secoo.mall.common.util.json.FastJsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.ArrayUtils;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
@Slf4j
public class BeanUtil extends BeanUtils {
private static final String[] DEFUALT_IGNORE_KEY = {"class", "empty"};
......@@ -54,8 +58,37 @@ public class BeanUtil extends BeanUtils {
try {
copyProperties(dest, orig);
} catch (Exception e) {
log.error("copyProps e:", e);
throw new BusinessException(CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION);
}
}
public static void copyProps(Object dest, Object orig, boolean ignoreNullFlag) {
PropertyDescriptor[] origDescriptors = PropertyUtils.getPropertyDescriptors(orig);
for (int i = 0; i < origDescriptors.length; i++) {
String name = origDescriptors[i].getName();
if ("class".equals(name)) {
continue; // No point in trying to set an object's class
}
if (PropertyUtils.isReadable(orig, name) &&
PropertyUtils.isWriteable(dest, name)) {
try {
Object value = PropertyUtils.getProperty(orig, name);
if (ignoreNullFlag) {
if (value != null) {
copyProperty(dest, name, value);
}
} else {
copyProperty(dest, name, value);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}
}
}
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-datasource</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -2,6 +2,8 @@ package com.secoo.mall.datasource.config;
import lombok.Data;
import java.util.Properties;
@Data
public class MatrixDataSourceConfig implements DataSourceConfig {
......@@ -22,6 +24,7 @@ public class MatrixDataSourceConfig implements DataSourceConfig {
private long idleTimeout = IDLE_TIMEOUT;
private long maxLifetime = MAX_LIFETIME;
public void setName(String name) {
this.name = POOL_NAME_PRIFIX + name;
}
......@@ -76,4 +79,5 @@ public class MatrixDataSourceConfig implements DataSourceConfig {
this.maxPoolSize = maxPoolSize;
}
}
......@@ -7,6 +7,8 @@ import lombok.Data;
public class MatrixDataSourceProperties extends MatrixDataSourceConfig {
public static final String PREFIX = "spring.datasource.matrix";
public MatrixDataSourceProperties() {
}
......
......@@ -15,10 +15,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.reflect.MethodUtils;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -26,6 +24,7 @@ import java.util.stream.Collectors;
*/
@Slf4j
public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends AbsDataSourceProvider<T> {
/**
* 从appollo加载配置信息
*
......@@ -47,6 +46,8 @@ public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends
Map<String, List<String>> propertyMap = propertyNames.stream().filter(pro -> pro.contains(MatrixDataSourceProperties.PREFIX)).map(pro -> pro.replace(MatrixDataSourceProperties.PREFIX, ""))
.collect(Collectors.groupingBy(str -> str.split(DataSourceConstant.PROPETY_SPLIT_CHAR)[1]));
Map<String, Class> fieldMap = getFieldMap();
try {
for (Map.Entry<String, List<String>> entry : propertyMap.entrySet()) {
String dsName = entry.getKey();
......@@ -54,11 +55,15 @@ public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends
matrixDataSourceProperties.setName(dsName);
for (String property : entry.getValue()) {
String propertyFullPath = MatrixDataSourceProperties.PREFIX + property;
String value = decryptPropertyItemValue(appConfig.getProperty(propertyFullPath, ""));
Object value = decryptPropertyItemValue(appConfig.getProperty(propertyFullPath, ""));
//得到实际的属性,首字母大写
String beanProperty = StringUtil.capitalize(property.split(DataSourceConstant.PROPETY_SPLIT_CHAR)[2]);
String beanProperty = property.split(DataSourceConstant.PROPETY_SPLIT_CHAR)[2];
//转换为真实类型数据
if(fieldMap.containsKey(beanProperty)){
value = MethodUtils.invokeExactStaticMethod(fieldMap.get(beanProperty), "valueOf", value);
}
MethodUtils.invokeExactMethod(matrixDataSourceProperties, "set" + beanProperty, value);
MethodUtils.invokeExactMethod(matrixDataSourceProperties, "set" + StringUtil.capitalize(beanProperty), value);
}
log.info("init datasource name:{}", dsName);
list.add(matrixDataSourceProperties);
......@@ -77,4 +82,22 @@ public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends
String acccessToken = appConfig.getProperty("config.app.security.accessToken", "default");
SysUtil.setProperty("accessToken", acccessToken);
}
private Map<String, Class> getFieldMap() {
List<Field> fieldList = new ArrayList<>();
Class tempClass = getEntryClass();
while (tempClass != null) {
fieldList.addAll(Arrays.asList(tempClass.getDeclaredFields()));
tempClass = tempClass.getSuperclass();
}
Map<String, Class> map = new HashMap<>();
//过滤String
fieldList = fieldList.stream().filter(field -> !field.getType().getSimpleName().contains("String")).collect(Collectors.toList());
for (Field field : fieldList) {
map.put(field.getName(), field.getType());
}
return map;
}
}
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-datasource</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
package com.secoo.mall.datasource.factory;
import com.alibaba.druid.pool.DruidDataSource;
import com.secoo.mall.common.util.bean.BeanUtil;
import com.secoo.mall.datasource.properties.MatrixDruidDataSourceProperties;
import lombok.extern.slf4j.Slf4j;
......@@ -13,6 +14,7 @@ public class DruidDataSourceFactory extends AbsDataSourceFactory<DruidDataSource
@Override
protected DruidDataSource convertAndCreate(MatrixDruidDataSourceProperties config) {
DruidDataSource dataSource = new DruidDataSource();
BeanUtil.copyProps(dataSource, config, true);
dataSource.setName(config.getName());
dataSource.setUrl(config.getUrl());
dataSource.setUsername(config.getUsername());
......@@ -22,7 +24,6 @@ public class DruidDataSourceFactory extends AbsDataSourceFactory<DruidDataSource
dataSource.setPhyTimeoutMillis(config.getConnectionTimeout());
dataSource.setTimeBetweenEvictionRunsMillis(config.getIdleTimeout());
dataSource.setMaxEvictableIdleTimeMillis(config.getMaxLifetime());
try {
dataSource.init();
} catch (SQLException e) {
......
package com.secoo.mall.datasource.properties;
import com.alibaba.druid.pool.DruidAbstractDataSource;
import lombok.Data;
import java.util.Properties;
@Data
public class MatrixDruidDataSourceProperties extends MatrixDataSourceProperties {
public static final String PREFIX = MatrixDataSourceProperties.PREFIX + ".druid";
private Long timeBetweenEvictionRunsMillis= DruidAbstractDataSource.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
private Long timeBetweenLogStatsMillis;
private Integer statSqlMaxSize;
private Long minEvictableIdleTimeMillis;
private Long maxEvictableIdleTimeMillis;
private Boolean testWhileIdle;
private Boolean testOnBorrow;
private Boolean testOnReturn;
private String validationQuery;
private Integer validationQueryTimeout;
private Boolean useGlobalDataSourceStat;
private Boolean asyncInit;
private String filters;
private Boolean clearFiltersEnable;
private Boolean resetStatEnable;
private Integer notFullTimeoutRetryCount;
private Integer maxWaitThreadCount;
private Boolean failFast;
private Long phyTimeoutMillis;
private Boolean keepAlive;
private Boolean poolPreparedStatements;
private Boolean initVariants;
private Boolean initGlobalVariants;
private Boolean useUnfairLock;
private Boolean killWhenSocketReadTimeout;
private Properties connectionProperties;
private Integer maxPoolPreparedStatementPerConnectionSize;
private String initConnectionSqls;
private Boolean sharePreparedStatements=false;
private Integer connectionErrorRetryAttempts=1;
private Boolean breakAfterAcquireFailure;
private Boolean removeAbandoned;
private Integer removeAbandonedTimeoutMillis;
private Boolean logAbandoned;
private String publicKey;
}
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -21,7 +21,7 @@
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-core</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-mq</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-mq</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-mybatis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-mybatis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -50,12 +50,6 @@ public class MatrixMybatisAutoConfiguration {
log.info("Init MatrixDataSouceAutoConfiguration");
}
@Bean
@ConditionalOnMissingBean(DataSourceProvider.class)
public DataSourceProvider dataSourceProvider() {
return new ApolloDruidDataSourceProvider();
}
/**
* 如果没有声明,则使用默认的
*
......@@ -63,16 +57,10 @@ public class MatrixMybatisAutoConfiguration {
*/
@Bean
@ConditionalOnMissingBean(DataSource.class)
public DataSource dataSource(DataSourceProvider dataSourceProvider) {
public DataSource dataSource() {
return new MatrixDataSource("01-rw");
}
@Bean
@ConditionalOnMissingBean(DataSourceFactory.class)
public DataSourceFactory dataSourceFactory() {
return new DruidDataSourceFactory();
}
@Bean
@ConditionalOnMissingBean(SqlSessionFactory.class)
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -25,17 +25,17 @@
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-core</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-druid</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-protocol</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-protocol</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-protocol</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-protocol</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-protocol</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -29,27 +29,27 @@
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-core</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-web-core</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-core</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-web-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<!-- Aapche Dubbo -->
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -6,7 +6,7 @@
<groupId>com.secoo.mall</groupId>
<artifactId>matrix</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
<packaging>pom</packaging>
......@@ -46,92 +46,92 @@
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>logger-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>monitor-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>common-core</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>config-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>common-util</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>redis-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-druid</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>mongodb-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>elasticsearch-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-rocketmq-core</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-rocketmq-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>openfeign-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-core</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-core</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-web-core</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-web-starter</artifactId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</dependency>
<dependency>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.6.RELEASE</version>
<version>1.2.7.RELEASE</version>
</parent>
<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