jar包版本:druid-1.0.15.jar
cmd命令行执行
java -cp druid-1.0.15.jar com.alibaba.druid.filter.config.ConfigTools 加密串
得到密文
package com.heli.core.user.common;
import com.alibaba.druid.filter.config.ConfigTools;
import com.alibaba.druid.pool.DruidDataSource;
/**
* 用来解密配置中的密文(重点配置,在这里扩展用户名的解密)
* setUsername(name) 方法对应xml中的一个property属性,password默认加密不需要重写,
* 还可以加密url 重写setUrl(url)
*/
@SuppressWarnings("all")
public class DecryptDruidSource extends DruidDataSource{
@Override
public void setUsername(String username) {
try {
username = ConfigTools.decrypt(username);
} catch (Exception e) {
e.printStackTrace();
}
super.setUsername(username);
}
}
<bean id="dataSource" class="com.heli.core.user.common.DecryptDruidSource">
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<!-- config.decrypt=true -->
<property name="filters" value="config" />
<property name="connectionProperties" value="config.decrypt=true" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${initialSize}" />
<!-- 连接池最大使用连接数量 -->
<property name="maxActive" value="${maxActive}" />
<!-- 连接池最大空闲 这个参数已经被弃用 <property name="maxIdle" value="${maxIdle}"></property> -->
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${minIdle}"></property>
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${maxWait}"></property>
<property name="validationQuery" value="${validationQuery}" />
<property name="testWhileIdle" value="${testWhileIdle}" />
<property name="testOnBorrow" value="${testOnBorrow}" />
<property name="testOnReturn" value="${testOnReturn}" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" />
<!-- 关闭长时间不使用的连接 -->
<!-- 打开removeAbandoned功能 -->
<property name="removeAbandoned" value="${removeAbandoned}" />
<!-- 1200秒,也就是20分钟 -->
<property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="${logAbandoned}" />
</bean>
#mysql
username=f0PSl0Lzxh6CxzuFIdEg+wVx045fSE2VtUP45G9HH2cjVQnmGGgcK5CLzNUJoR6tGwRO44h74OxrBWuDzWC8jg==
password=f0PSl0Lzxh6CxzuFIdEg+wVx045fSE2VtUP45G9HH2cjVQnmGGgcK5CLzNUJoR6tGwRO44h74OxrBWuDzWC8jg==
url=jdbc:mysql://192.168.1.194/user?characterEncoding=utf-8
driver=com.mysql.jdbc.Driver
initialSize=5
minIdle=5
maxActive=20
maxWait=60000
timeBetweenEvictionRunsMillis=60000
minEvictableIdleTimeMillis=30000
validationQuery=SELECT 1
testWhileIdle=true
testOnBorrow=true
testOnReturn=true
filters=stat,log4j
removeAbandoned=true
removeAbandonedTimeout=1200
logAbandoned=true