Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
徐少华
midjourney-proxy
Commits
517ca0e5
Commit
517ca0e5
authored
Dec 24, 2018
by
songxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
数据库密码加密处理
parent
7335b717
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
312 additions
and
134 deletions
+312
-134
bootstrap.yml
pcloud-common-config/src/main/resources.prod/bootstrap.yml
+17
-0
bootstrap.yml
pcloud-common-config/src/main/resources.uat/bootstrap.yml
+17
-0
DataSourceConfig.java
...a/com/pcloud/common/core/datasource/DataSourceConfig.java
+278
-134
No files found.
pcloud-common-config/src/main/resources.prod/bootstrap.yml
View file @
517ca0e5
...
...
@@ -10,6 +10,23 @@ spring:
loadbalancer
:
retry
:
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
:
influx
:
uri
:
http://192.168.83.241:8086/write
...
...
pcloud-common-config/src/main/resources.uat/bootstrap.yml
View file @
517ca0e5
...
...
@@ -10,6 +10,23 @@ spring:
loadbalancer
:
retry
:
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
:
influx
:
uri
:
http://192.168.83.241:8086/write
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/datasource/DataSourceConfig.java
View file @
517ca0e5
...
...
@@ -16,6 +16,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
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.Configuration
;
import
org.springframework.context.annotation.Primary
;
...
...
@@ -25,139 +26,282 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import
com.alibaba.druid.pool.DruidDataSource
;
@Configuration
@MapperScan
(
basePackages
=
DataSourceConfig
.
PACKAGE
,
sqlSessionFactoryRef
=
"sqlSessionFactory"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource"
)
@MapperScan
(
basePackages
=
DataSourceConfig
.
PACKAGE
,
sqlSessionFactoryRef
=
"sqlSessionFactory"
)
public
class
DataSourceConfig
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
DataSourceConfig
.
class
);
static
final
String
PACKAGE
=
"com.pcloud.common.core.dao"
;
@Value
(
"${spring.datasource.url}"
)
private
String
dbUrl
;
@Value
(
"${spring.datasource.type}"
)
private
String
dbType
;
@Value
(
"${spring.datasource.username}"
)
private
String
username
;
@Value
(
"${spring.datasource.password}"
)
private
String
password
;
@Value
(
"${spring.datasource.driver-class-name}"
)
private
String
driverClassName
;
@Value
(
"${spring.datasource.initialSize}"
)
private
int
initialSize
;
@Value
(
"${spring.datasource.minIdle}"
)
private
int
minIdle
;
@Value
(
"${spring.datasource.maxActive}"
)
private
int
maxActive
;
@Value
(
"${spring.datasource.maxWait}"
)
private
int
maxWait
;
@Value
(
"${spring.datasource.timeBetweenEvictionRunsMillis}"
)
private
int
timeBetweenEvictionRunsMillis
;
@Value
(
"${spring.datasource.minEvictableIdleTimeMillis}"
)
private
int
minEvictableIdleTimeMillis
;
@Value
(
"${spring.datasource.validationQuery}"
)
private
String
validationQuery
;
@Value
(
"${spring.datasource.testWhileIdle}"
)
private
boolean
testWhileIdle
;
@Value
(
"${spring.datasource.testOnBorrow}"
)
private
boolean
testOnBorrow
;
@Value
(
"${spring.datasource.testOnReturn}"
)
private
boolean
testOnReturn
;
@Value
(
"${spring.datasource.poolPreparedStatements}"
)
private
boolean
poolPreparedStatements
;
@Value
(
"${spring.datasource.filters}"
)
private
String
filters
;
@Value
(
"${spring.datasource.connectionProperties}"
)
private
String
connectionProperties
;
@Value
(
"${mybatis.mapper-locations}"
)
private
String
mapperLocations
;
@Value
(
"${mybatis.type-aliases-package}"
)
private
String
typeAliasesPackage
;
// @Value("${spring.datasource.useGlobalDataSourceStat}")
// private boolean useGlobalDataSourceStat;
//
// @Value("${spring.datasource.druidLoginName}")
// private String druidLoginName;
//
// @Value("${spring.datasource.druidPassword}")
// private String druidPassword;
@Bean
(
name
=
"druidDataSource"
)
@Primary
//不要漏了这
public
DataSource
dataSource
(){
DruidDataSource
datasource
=
new
DruidDataSource
();
try
{
datasource
.
setUrl
(
this
.
dbUrl
);
datasource
.
setDbType
(
dbType
);
datasource
.
setUsername
(
username
);
datasource
.
setPassword
(
password
);
datasource
.
setDriverClassName
(
driverClassName
);
datasource
.
setInitialSize
(
initialSize
);
datasource
.
setMinIdle
(
minIdle
);
datasource
.
setMaxActive
(
maxActive
);
datasource
.
setMaxWait
(
maxWait
);
datasource
.
setTimeBetweenEvictionRunsMillis
(
timeBetweenEvictionRunsMillis
);
datasource
.
setMinEvictableIdleTimeMillis
(
minEvictableIdleTimeMillis
);
datasource
.
setValidationQuery
(
validationQuery
);
datasource
.
setTestWhileIdle
(
testWhileIdle
);
datasource
.
setTestOnBorrow
(
testOnBorrow
);
datasource
.
setTestOnReturn
(
testOnReturn
);
datasource
.
setPoolPreparedStatements
(
poolPreparedStatements
);
datasource
.
setFilters
(
filters
);
datasource
.
setConnectionProperties
(
connectionProperties
);
// datasource.setUseGlobalDataSourceStat(useGlobalDataSourceStat);
ArrayList
<
String
>
arr
=
new
ArrayList
<>();
arr
.
add
(
"set names utf8mb4;"
);
datasource
.
setConnectionInitSqls
(
arr
);
}
catch
(
SQLException
e
)
{
logger
.
error
(
"druid configuration initialization filter"
,
e
);
}
return
datasource
;
}
@Bean
(
name
=
"transactionManager"
)
public
DataSourceTransactionManager
transactionManager
()
{
logger
.
info
(
"【DataSource】初始化TransactionManager事务管理器,<START>"
);
return
new
DataSourceTransactionManager
(
dataSource
());
}
@Bean
(
name
=
"sqlSessionFactory"
)
@Autowired
public
SqlSessionFactory
sqlSessionFactory
(
ExecutorInterceptor
interceptor
)
throws
Exception
{
logger
.
info
(
"【DataSource】初始化SqlSessionFactory,<START>"
);
final
SqlSessionFactoryBean
sessionFactoryBean
=
new
SqlSessionFactoryBean
();
sessionFactoryBean
.
setDataSource
(
dataSource
());
sessionFactoryBean
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
().
getResources
(
mapperLocations
));
sessionFactoryBean
.
setVfs
(
SpringBootVFS
.
class
);
sessionFactoryBean
.
setTypeAliasesPackage
(
typeAliasesPackage
);
sessionFactoryBean
.
setPlugins
(
new
Interceptor
[]{
interceptor
});
return
sessionFactoryBean
.
getObject
();
}
@Bean
(
name
=
"sqlSessionTemplate"
)
@Autowired
public
SqlSessionTemplate
sqlSessionTemplate
(
ExecutorInterceptor
interceptor
)
throws
Exception
{
logger
.
info
(
"【DataSource】初始化SqlSessionTemplate,<START>"
);
final
SqlSessionTemplate
sessionFactoryBean
=
new
SqlSessionTemplate
(
sqlSessionFactory
(
interceptor
));
return
sessionFactoryBean
;
}
private
Logger
logger
=
LoggerFactory
.
getLogger
(
DataSourceConfig
.
class
);
static
final
String
PACKAGE
=
"com.pcloud.common.core.dao"
;
private
String
url
;
private
String
type
;
private
String
username
;
private
String
password
;
private
String
driverClassName
;
private
int
initialSize
;
private
int
minIdle
;
private
int
maxActive
;
private
int
maxWait
;
private
int
timeBetweenEvictionRunsMillis
;
private
int
minEvictableIdleTimeMillis
;
private
String
validationQuery
;
private
boolean
testWhileIdle
;
private
boolean
testOnBorrow
;
private
boolean
testOnReturn
;
private
boolean
poolPreparedStatements
;
private
String
filtersNew
;
private
String
connectionPropertiesNew
;
@Value
(
"${mybatis.mapper-locations}"
)
private
String
mapperLocations
;
@Value
(
"${mybatis.type-aliases-package}"
)
private
String
typeAliasesPackage
;
// @Value("${spring.datasource.useGlobalDataSourceStat}")
// private boolean useGlobalDataSourceStat;
//
// @Value("${spring.datasource.druidLoginName}")
// private String druidLoginName;
//
// @Value("${spring.datasource.druidPassword}")
// private String druidPassword;
@Bean
(
name
=
"druidDataSource"
)
@Primary
// 不要漏了这
public
DataSource
dataSource
()
{
DruidDataSource
datasource
=
new
DruidDataSource
();
try
{
datasource
.
setUrl
(
url
);
datasource
.
setDbType
(
type
);
datasource
.
setUsername
(
username
);
datasource
.
setPassword
(
password
);
datasource
.
setDriverClassName
(
driverClassName
);
datasource
.
setInitialSize
(
initialSize
);
datasource
.
setMinIdle
(
minIdle
);
datasource
.
setMaxActive
(
maxActive
);
datasource
.
setMaxWait
(
maxWait
);
datasource
.
setTimeBetweenEvictionRunsMillis
(
timeBetweenEvictionRunsMillis
);
datasource
.
setMinEvictableIdleTimeMillis
(
minEvictableIdleTimeMillis
);
datasource
.
setValidationQuery
(
validationQuery
);
datasource
.
setTestWhileIdle
(
testWhileIdle
);
datasource
.
setTestOnBorrow
(
testOnBorrow
);
datasource
.
setTestOnReturn
(
testOnReturn
);
datasource
.
setPoolPreparedStatements
(
poolPreparedStatements
);
datasource
.
setFilters
(
filtersNew
);
datasource
.
setConnectionProperties
(
connectionPropertiesNew
);
// datasource.setUseGlobalDataSourceStat(useGlobalDataSourceStat);
ArrayList
<
String
>
arr
=
new
ArrayList
<>();
arr
.
add
(
"set names utf8mb4;"
);
datasource
.
setConnectionInitSqls
(
arr
);
}
catch
(
SQLException
e
)
{
logger
.
error
(
"druid configuration initialization filter"
,
e
);
}
return
datasource
;
}
@Bean
(
name
=
"transactionManager"
)
public
DataSourceTransactionManager
transactionManager
()
{
logger
.
info
(
"【DataSource】初始化TransactionManager事务管理器,<START>"
);
return
new
DataSourceTransactionManager
(
dataSource
());
}
@Bean
(
name
=
"sqlSessionFactory"
)
@Autowired
public
SqlSessionFactory
sqlSessionFactory
(
ExecutorInterceptor
interceptor
)
throws
Exception
{
logger
.
info
(
"【DataSource】初始化SqlSessionFactory,<START>"
);
final
SqlSessionFactoryBean
sessionFactoryBean
=
new
SqlSessionFactoryBean
();
sessionFactoryBean
.
setDataSource
(
dataSource
());
sessionFactoryBean
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
().
getResources
(
mapperLocations
));
sessionFactoryBean
.
setVfs
(
SpringBootVFS
.
class
);
sessionFactoryBean
.
setTypeAliasesPackage
(
typeAliasesPackage
);
sessionFactoryBean
.
setPlugins
(
new
Interceptor
[]
{
interceptor
});
return
sessionFactoryBean
.
getObject
();
}
@Bean
(
name
=
"sqlSessionTemplate"
)
@Autowired
public
SqlSessionTemplate
sqlSessionTemplate
(
ExecutorInterceptor
interceptor
)
throws
Exception
{
logger
.
info
(
"【DataSource】初始化SqlSessionTemplate,<START>"
);
final
SqlSessionTemplate
sessionFactoryBean
=
new
SqlSessionTemplate
(
sqlSessionFactory
(
interceptor
));
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment