数据库联接池有很多种,除了c3p0,dbcp,还有druid,而且现在用的也比较火。

    今天把配置过程记录下来。

    1,pom.xml 配置

      <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.0.23</version>
    </dependency>


    2,jndi配置

      jndi配置-喧哗博客


    3,web.xml 配置


     <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> 
    4,启动服务,在浏览器输入 http://localhost:8080/druid/index.html 就会展示默认的html页面


    druid监控-喧哗博客


    如果还需要使用Web应用、URI监控、Session监控、Spring监控等则还需要继续增加配置。

    5、Wen应用配置

    WebStatFilter用于采集web-jdbc关联监控的数据

    在Web.xml中增加配置,就可以使用Web应用、URI监控、Session监控等功能

     <filter>
        <filter-name>DruidWebStatFilter</filter-name>
        <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
        <init-param>
            <param-name>exclusions</param-name>
            <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/console/*</param-value>
        </init-param>
        <init-param>
        	<param-name>profileEnable</param-name>
        	<param-value>true</param-value>
    	</init-param>
    	<init-param>
            <param-name>principalCookieName</param-name>
            <param-value>USER_COOKIE</param-value>
        </init-param>
        <init-param>
            <param-name>principalSessionName</param-name>
            <param-value>USER_SESSION</param-value>
        </init-param>
      </filter>
      <filter-mapping>
        <filter-name>DruidWebStatFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
     
    
    6,spring配置
    <bean id="druid-stat-interceptor"
    		class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">
    	</bean>
    	<bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut"
    		scope="prototype">
    		<property name="patterns">
    			<list>
    				<value>com.bdbvip.*.service.*</value>
    				<value>com.bdbvip.*.dao.*</value>
    			</list>
    		</property>
    	</bean>
    
    	<aop:config proxy-target-class="true">
    		<aop:advisor advice-ref="druid-stat-interceptor"
    			pointcut-ref="druid-stat-pointcut" />
    	</aop:config>
     
    
    至此已经全部配置完毕。


    联系QQ:343886028 --加QQ群 145315854