Commit 517ca0e5 by songxiang

数据库密码加密处理

parent 7335b717
...@@ -10,6 +10,23 @@ spring: ...@@ -10,6 +10,23 @@ spring:
loadbalancer: loadbalancer:
retry: retry:
enabled: true enabled: true
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
initialSize: 2
minIdle: 5
maxActive: 50
maxWait: 60000
timeBetweenEvictionRunsMillis: 3000
minEvictableIdleTimeMillis: 3600000
validationQuery: SELECT 'x' FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
connectionPropertiesNew: config.decrypt=true;config.decrypt.key=${spring.datasource.publicKey}
filtersNew: config
metrics: metrics:
influx: influx:
uri: http://192.168.83.241:8086/write uri: http://192.168.83.241:8086/write
......
...@@ -10,6 +10,23 @@ spring: ...@@ -10,6 +10,23 @@ spring:
loadbalancer: loadbalancer:
retry: retry:
enabled: true enabled: true
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
initialSize: 2
minIdle: 5
maxActive: 50
maxWait: 60000
timeBetweenEvictionRunsMillis: 3000
minEvictableIdleTimeMillis: 3600000
validationQuery: SELECT 'x' FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
connectionPropertiesNew: config.decrypt=true;config.decrypt.key=${spring.datasource.publicKey}
filtersNew: config
metrics: metrics:
influx: influx:
uri: http://192.168.83.241:8086/write uri: http://192.168.83.241:8086/write
......
...@@ -16,6 +16,7 @@ import org.slf4j.Logger; ...@@ -16,6 +16,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
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 org.springframework.context.annotation.Primary;
...@@ -25,65 +26,48 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; ...@@ -25,65 +26,48 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidDataSource;
@Configuration @Configuration
@MapperScan(basePackages = DataSourceConfig.PACKAGE,sqlSessionFactoryRef = "sqlSessionFactory") @ConfigurationProperties(prefix = "spring.datasource")
@MapperScan(basePackages = DataSourceConfig.PACKAGE, sqlSessionFactoryRef = "sqlSessionFactory")
public class DataSourceConfig { public class DataSourceConfig {
private Logger logger = LoggerFactory.getLogger(DataSourceConfig.class); private Logger logger = LoggerFactory.getLogger(DataSourceConfig.class);
static final String PACKAGE = "com.pcloud.common.core.dao"; static final String PACKAGE = "com.pcloud.common.core.dao";
@Value("${spring.datasource.url}") private String url;
private String dbUrl;
@Value("${spring.datasource.type}") private String type;
private String dbType;
@Value("${spring.datasource.username}")
private String username; private String username;
@Value("${spring.datasource.password}")
private String password; private String password;
@Value("${spring.datasource.driver-class-name}")
private String driverClassName; private String driverClassName;
@Value("${spring.datasource.initialSize}")
private int initialSize; private int initialSize;
@Value("${spring.datasource.minIdle}")
private int minIdle; private int minIdle;
@Value("${spring.datasource.maxActive}")
private int maxActive; private int maxActive;
@Value("${spring.datasource.maxWait}")
private int maxWait; private int maxWait;
@Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
private int timeBetweenEvictionRunsMillis; private int timeBetweenEvictionRunsMillis;
@Value("${spring.datasource.minEvictableIdleTimeMillis}")
private int minEvictableIdleTimeMillis; private int minEvictableIdleTimeMillis;
@Value("${spring.datasource.validationQuery}")
private String validationQuery; private String validationQuery;
@Value("${spring.datasource.testWhileIdle}")
private boolean testWhileIdle; private boolean testWhileIdle;
@Value("${spring.datasource.testOnBorrow}")
private boolean testOnBorrow; private boolean testOnBorrow;
@Value("${spring.datasource.testOnReturn}")
private boolean testOnReturn; private boolean testOnReturn;
@Value("${spring.datasource.poolPreparedStatements}")
private boolean poolPreparedStatements; private boolean poolPreparedStatements;
@Value("${spring.datasource.filters}") private String filtersNew;
private String filters;
@Value("${spring.datasource.connectionProperties}") private String connectionPropertiesNew;
private String connectionProperties;
@Value("${mybatis.mapper-locations}") @Value("${mybatis.mapper-locations}")
private String mapperLocations; private String mapperLocations;
...@@ -91,22 +75,22 @@ public class DataSourceConfig { ...@@ -91,22 +75,22 @@ public class DataSourceConfig {
@Value("${mybatis.type-aliases-package}") @Value("${mybatis.type-aliases-package}")
private String typeAliasesPackage; private String typeAliasesPackage;
// @Value("${spring.datasource.useGlobalDataSourceStat}") // @Value("${spring.datasource.useGlobalDataSourceStat}")
// private boolean useGlobalDataSourceStat; // private boolean useGlobalDataSourceStat;
// //
// @Value("${spring.datasource.druidLoginName}") // @Value("${spring.datasource.druidLoginName}")
// private String druidLoginName; // private String druidLoginName;
// //
// @Value("${spring.datasource.druidPassword}") // @Value("${spring.datasource.druidPassword}")
// private String druidPassword; // private String druidPassword;
@Bean(name="druidDataSource") @Bean(name = "druidDataSource")
@Primary //不要漏了这 @Primary // 不要漏了这
public DataSource dataSource(){ public DataSource dataSource() {
DruidDataSource datasource = new DruidDataSource(); DruidDataSource datasource = new DruidDataSource();
try { try {
datasource.setUrl(this.dbUrl); datasource.setUrl(url);
datasource.setDbType(dbType); datasource.setDbType(type);
datasource.setUsername(username); datasource.setUsername(username);
datasource.setPassword(password); datasource.setPassword(password);
datasource.setDriverClassName(driverClassName); datasource.setDriverClassName(driverClassName);
...@@ -121,9 +105,9 @@ public class DataSourceConfig { ...@@ -121,9 +105,9 @@ public class DataSourceConfig {
datasource.setTestOnBorrow(testOnBorrow); datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn); datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements); datasource.setPoolPreparedStatements(poolPreparedStatements);
datasource.setFilters(filters); datasource.setFilters(filtersNew);
datasource.setConnectionProperties(connectionProperties); datasource.setConnectionProperties(connectionPropertiesNew);
// datasource.setUseGlobalDataSourceStat(useGlobalDataSourceStat); // datasource.setUseGlobalDataSourceStat(useGlobalDataSourceStat);
ArrayList<String> arr = new ArrayList<>(); ArrayList<String> arr = new ArrayList<>();
arr.add("set names utf8mb4;"); arr.add("set names utf8mb4;");
datasource.setConnectionInitSqls(arr); datasource.setConnectionInitSqls(arr);
...@@ -139,7 +123,6 @@ public class DataSourceConfig { ...@@ -139,7 +123,6 @@ public class DataSourceConfig {
return new DataSourceTransactionManager(dataSource()); return new DataSourceTransactionManager(dataSource());
} }
@Bean(name = "sqlSessionFactory") @Bean(name = "sqlSessionFactory")
@Autowired @Autowired
public SqlSessionFactory sqlSessionFactory(ExecutorInterceptor interceptor) throws Exception { public SqlSessionFactory sqlSessionFactory(ExecutorInterceptor interceptor) throws Exception {
...@@ -149,7 +132,7 @@ public class DataSourceConfig { ...@@ -149,7 +132,7 @@ public class DataSourceConfig {
sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations)); sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
sessionFactoryBean.setVfs(SpringBootVFS.class); sessionFactoryBean.setVfs(SpringBootVFS.class);
sessionFactoryBean.setTypeAliasesPackage(typeAliasesPackage); sessionFactoryBean.setTypeAliasesPackage(typeAliasesPackage);
sessionFactoryBean.setPlugins(new Interceptor[]{interceptor}); sessionFactoryBean.setPlugins(new Interceptor[] { interceptor });
return sessionFactoryBean.getObject(); return sessionFactoryBean.getObject();
} }
...@@ -160,4 +143,165 @@ public class DataSourceConfig { ...@@ -160,4 +143,165 @@ public class DataSourceConfig {
final SqlSessionTemplate sessionFactoryBean = new SqlSessionTemplate(sqlSessionFactory(interceptor)); final SqlSessionTemplate sessionFactoryBean = new SqlSessionTemplate(sqlSessionFactory(interceptor));
return sessionFactoryBean; return sessionFactoryBean;
} }
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDriverClassName() {
return driverClassName;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
public int getInitialSize() {
return initialSize;
}
public void setInitialSize(int initialSize) {
this.initialSize = initialSize;
}
public int getMinIdle() {
return minIdle;
}
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
public int getMaxActive() {
return maxActive;
}
public void setMaxActive(int maxActive) {
this.maxActive = maxActive;
}
public int getMaxWait() {
return maxWait;
}
public void setMaxWait(int maxWait) {
this.maxWait = maxWait;
}
public int getTimeBetweenEvictionRunsMillis() {
return timeBetweenEvictionRunsMillis;
}
public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
}
public int getMinEvictableIdleTimeMillis() {
return minEvictableIdleTimeMillis;
}
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
public String getValidationQuery() {
return validationQuery;
}
public void setValidationQuery(String validationQuery) {
this.validationQuery = validationQuery;
}
public boolean isTestWhileIdle() {
return testWhileIdle;
}
public void setTestWhileIdle(boolean testWhileIdle) {
this.testWhileIdle = testWhileIdle;
}
public boolean isTestOnBorrow() {
return testOnBorrow;
}
public void setTestOnBorrow(boolean testOnBorrow) {
this.testOnBorrow = testOnBorrow;
}
public boolean isTestOnReturn() {
return testOnReturn;
}
public void setTestOnReturn(boolean testOnReturn) {
this.testOnReturn = testOnReturn;
}
public boolean isPoolPreparedStatements() {
return poolPreparedStatements;
}
public void setPoolPreparedStatements(boolean poolPreparedStatements) {
this.poolPreparedStatements = poolPreparedStatements;
}
public String getFiltersNew() {
return filtersNew;
}
public void setFiltersNew(String filtersNew) {
this.filtersNew = filtersNew;
}
public String getConnectionPropertiesNew() {
return connectionPropertiesNew;
}
public void setConnectionPropertiesNew(String connectionPropertiesNew) {
this.connectionPropertiesNew = connectionPropertiesNew;
}
public String getMapperLocations() {
return mapperLocations;
}
public void setMapperLocations(String mapperLocations) {
this.mapperLocations = mapperLocations;
}
public String getTypeAliasesPackage() {
return typeAliasesPackage;
}
public void setTypeAliasesPackage(String typeAliasesPackage) {
this.typeAliasesPackage = typeAliasesPackage;
}
} }
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