com.alibaba.druid.pool.DruidDataSource连接池
<bean id="userDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close" p:url="${datasource.user.url}" p:username="${datasource.user.username}" p:password="${datasource.user.password}" p:initialSize="${datasource.user.initialSize}" p:minIdle="${datasource.user.minIdle}" p:maxActive="${datasource.user.maxActive}" p:maxWait="${datasource.user.maxWait}" p:timeBetweenEvictionRunsMillis="${datasource.user.timeBetweenEvictionRunsMillis}" p:minEvictableIdleTimeMillis="${datasource.user.minEvictableIdleTimeMillis}" p:validationQuery="${datasource.user.validationQuery}" p:testWhileIdle="${datasource.user.testWhileIdle}" p:testOnBorrow="${datasource.user.testOnBorrow}" p:testOnReturn="${datasource.user.testOnReturn}" p:poolPreparedStatements="${datasource.user.poolPreparedStatements}" p:maxPoolPreparedStatementPerConnectionSize="${datasource.user.maxPoolPreparedStatementPerConnectionSize}" p:connectionProperties="config.decrypt=true;config.decrypt.key=${datasource.user.publickey}" p:filters="${datasource.user.filters}"> </bean> datasource.user.password=Lvn51mtSaiYw4Cb9JnIet9GwULZ4EdIt1rUmJdZ8durQwU+yG/N13hLSEQ6Qo29055BJrnfACRGxNXfLaOMXvQ== datasource.user.publickey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJUx7ok9nN+0TEiI4L+BlNPPc+NAqbgX9iVvX94o9rX7yMkrOLdHjwqb3I8g8WaTQO9sMDiEOHbylYo2LgKH8cMCAwEAAQ==
配置连接池的时候,使用加密的方法
找到druid.jar的目录,然后输入如下命令
java -cp druid-1.1.12.jar com.alibaba.druid.filter.config.ConfigTools myPassword
1.1.12——修改成你项目的版本号
myPassword——修改成你的数据库连接密码
结果:
privateKey:MIIBVgIBADANBgkqhkiG9w0BAQEFAASCAUAwggE8AgEAAkEA2mJYiCmr8Ilk8+H7i7+Zf
O8WL6Yb8+yG1FEIgBCAQ70fgQE2sKIPuWKL5cdsMNUY9Tcfxg1rbYf/3FR1wcD4tQIDAQABAkEAnU+kq
IkkI0RFpWzPD874GMf9Olu03RQv17d7oQzB6Ih6BS3t955ljWALJxRtcrzZVF9PZ1E9Cbd3ETdGI93Yz
QIhAO55gTA97s2GO73yAM5j+Cl6hgfRGlFSXWteB3rMuOxfAiEA6m7fiixVV449IHrFS7t3JUxeHeFkU
29iK1UwfM7o82sCIQC7A9h3P6p9zO4e+KD/OlDMHoTrrmUoLyKJ57SP7ep7mwIhALJD6zIbsi2pGKxZD
yweemRfZPYdzXdwrFq9JejSQevPAiBRnNDJNbCtJbSgnPY4UkH5BnT975Aur3Ny+qzfg7Otbw==
publicKey:MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANpiWIgpq/CJZPPh+4u/mXzvFi+mG/PshtRRCI
AQgEO9H4EBNrCiD7lii+XHbDDVGPU3H8YNa22H/9xUdcHA+LUCAwEAAQ==
password:EjeEp4n/CTo3/uA50YLp3X4WTPBIASVP1iXyiBsGtHmg12Lq5vzBvR2bUdKrKTZ8VzGhwm0
2B6ri+EfykbHhRA==
public key复制后放在yml配置的“connection-properties: config.decrypt=true;config.decrypt.key=” 后面,password:EjeEp4n复制后放到yml配置的password后面。