jar包版本:druid-1.0.15.jarjava
cmd命令行执行mysql
java -cp druid-1.0.15.jar com.alibaba.druid.filter.config.ConfigTools 加密串
获得密文spring
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