什么是 druid
Druid 是由阿里巴巴团队开发,Java 语言中最好的数据库连接池。Druid 能够提供强大的监控和扩展功能。
获取 druid
github:https://github.com/alibaba/druid
MAVEN:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
</dependency>
数据源配置
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${druid.url}" />
<property name="username" value="${druid.user}" />
<property name="password" value="${druid.password}" />
<property name="driverClassName" value="${druid.driver}" />
<property name="filters" value="config" />
<property name="maxActive" value="${druid.maxActive}" />
<property name="initialSize" value="${druid.initialSize}" />
<property name="maxWait" value="${druid.maxWait}" />
<property name="minIdle" value="${druid.minIdle}" />
<property name="timeBetweenEvictionRunsMillis" value="${druid.timeBetweenEvictionRunsMillis}" />
<property name="minEvictableIdleTimeMillis" value="${druid.minEvictableIdleTimeMillis}" />
<property name="validationQuery" value="${druid.validationQuery}" />
<property name="testWhileIdle" value="${druid.testWhileIdle}" />
<property name="testOnBorrow" value="${druid.testOnBorrow}" />
<property name="testOnReturn" value="${druid.testOnReturn}" />
<property name="maxOpenPreparedStatements" value="${druid.maxOpenPreparedStatements}" />
<property name="removeAbandoned" value="${druid.removeAbandoned}" />
<property name="removeAbandonedTimeout" value="${druid.removeAbandonedTimeout}" />
<property name="logAbandoned" value="${druid.logAbandoned}" />
<property name="connectionProperties" value="config.decrypt=true" />
bean>
properties
druid.driver=com.mysql.jdbc.Driver
druid.pool=1
druid.host=
druid.port=3306
druid.sid=
druid.url=jdbc:mysql://${druid.host}:${druid.port}/${druid.sid}?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true
druid.user=
druid.password=TVy7gh4GgZy8qVqexcf9PZ8/MaSc1wy+hR6ZreZvflZMXJiHWphRpCAyxVYnuH46vmpYKmeUPxYKYxRyCnyATA==
druid.maxActive=300
druid.initialSize=1
druid.maxWait=60000
druid.minIdle=10
druid.timeBetweenEvictionRunsMillis=60000
druid.minEvictableIdleTimeMillis=300000
druid.validationQuery=SELECT 'x'
druid.testWhileIdle=false
druid.testOnBorrow=false
druid.testOnReturn=false
druid.maxOpenPreparedStatements=50
druid.removeAbandoned=true
druid.removeAbandonedTimeout=1800
druid.logAbandoned=true
参数配置见 DruidDataSource 配置属性列表
加密工具
import com.alibaba.druid.filter.config.ConfigTools;
public class PwdTools {
/**
* 加密
*
* @param t 需要加密的密码
* @return
* @throws Exception
*/ public static String Decrypt(String t) throws Exception {
return ConfigTools.encrypt(t);
}
/**
* 解密
*
* @param t 需要解密的密文
* @return
* @throws Exception
*/ public static String Encrypt(String t) throws Exception {
return ConfigTools.decrypt(t);
}
public static void main(String[] args) throws Exception {
String pwd = "test";
pwd = PwdTools.Decrypt(pwd);
System.out.println(pwd);
pwd = PwdTools.Encrypt(pwd);
System.out.println(pwd);
}
}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于