阿里巴巴Druid连接池配置

Druid 是阿里巴巴的开源数据库连接池技术,相比dbcp、c3p0更优秀,具有密码加密、sql连接监控功能,无论在性能还是稳定性上表现都十分出色。

一、加入jar文件

maven仓库地址:http://central.maven.org/maven2/com/alibaba/druid/
jar包下载地址:http://central.maven.org/maven2/com/alibaba/druid/1.1.2/druid-1.1.2.jar

二、spring.xml配置:

在context.hibernate1.xml中进行配置,具体配置如下:

<context:property-placeholder location="classpath:jdbc.properties"/>  
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"  
        init-method="init" destroy-method="close">  
        <property name="driverClassName" value="${oracle.driver}" />  
        <property name="url" value="${oracle.url}" />  
        <property name="username" value="${oracle.username}" />  
        <property name="password" value="${oracle.password}" />         
        <property name="initialSize" value="${druid.initialSize}" />  
        <property name="maxActive" value="${druid.maxActive}" />  
        <property name="maxIdle" value="${druid.maxIdle}" />  
        <property name="minIdle" value="${druid.minIdle}" />  
        <property name="maxWait" value="${druid.maxWait}" />  
        <property name="removeAbandoned" value="${druid.removeAbandoned}" />  
        <property name="removeAbandonedTimeout" value="${druid.removeAbandonedTimeout}" />  
        <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="poolPreparedStatements" value="${druid.poolPreparedStatements}" />          
        <property name="maxPoolPreparedStatementPerConnectionSize" value="${druid.maxPoolPreparedStatementPerConnectionSize}" />  
          
          

           
           <property name="filters" value="config,stat" />  
           <property name="connectionProperties" value="config.decrypt=true;config.decrypt.key=${oracle.publickey}" />
    bean>

web.xml 中配置sql监控

    <servlet>
        <servlet-name>DruidStatView servlet-name>
        <servlet-class>com.alibaba.druid.support.http.StatViewServlet servlet-class>
    servlet>
    <servlet-mapping>
        <servlet-name>DruidStatView servlet-name>
        <url-pattern>/druid/*url-pattern>
    servlet-mapping>

jdbc.properties

   
oracle.driver = oracle.jdbc.driver.OracleDriver  
oracle.url = jdbc:oracle:thin:@localhost:1521:makecardcl  
oracle.username = MakeCard_CL  
oracle.password = ZWV95JNDIhKl90iz1hy0uc+n0Fav0LO/U/36PkO4AuXMnuz+MiXmkYDqeICk3ONeTeEDe/BctZ+pVwnB0sK51A==
oracle.publickey = MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIQdIhCTaX4fSqZaKcaGDODShQ8x832eLgM9IWQPlCxYSxaSwhsy/mKtq8bLuodVBGrDLSWLLbAdb5PX/ShyBaECAwEAAQ==
 
druid.initialSize = 3  
   
druid.maxActive = 10  
  
druid.maxIdle=5  
  
druid.minIdle = 2  
 
druid.maxWait = 60000  
   
druid.removeAbandoned = true  
  
druid.removeAbandonedTimeout = 180 
  
druid.timeBetweenEvictionRunsMillis = 60000  
 
druid.minEvictableIdleTimeMillis = 300000  
  
druid.validationQuery = SELECT 1 FROM DUAL 
 
druid.testWhileIdle = false  
  
druid.testOnBorrow = false  
  
druid.testOnReturn = false  
 
druid.poolPreparedStatements = true  
druid.maxPoolPreparedStatementPerConnectionSize = 100
filters =stat  

使用druid.jar 包生成密码

通过cmd命令,生产publickey ,password

Java -cp  druid-1.0.9.jar com.alibaba.druid.filter.config.ConfigTools  you_password

加密实现参考链接如下:
加密实现:http://blog.csdn.net/xlgen157387/article/details/51260930

访问内置监控页面

http://IP:Port/druid/index.html

参考地址

官方githup:https://github.com/alibaba/druid
详细参数说明:http://www.cnblogs.com/wuyun-blog/p/5679073.html

你可能感兴趣的:(java)