首页 > 代码库 > druid 使用及配置

druid 使用及配置

druid 数据源配置

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">  
            <property name="url" value="${ds1.url}" />  
            <property name="username" value="${ds1.username}" />  
            <property name="password" value="${ds1.password}" />  
                
<!--                 配置监控统计拦截的filters,去掉后监控界面sql无法统计 -->
            <property name="filters" value="stat" />  
            
<!--                 配置初始化大小、最小、最大 -->
            <property name="maxActive" value="20" />   
            <property name="initialSize" value="1" />  
            <property name="minIdle" value="1" />  
            
<!--                 配置获取连接等待超时的时间 -->
            <property name="maxWait" value="60000" />  
            
<!--                 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
            <property name="timeBetweenEvictionRunsMillis" value="3000" />  
                
<!--                 配置一个连接在池中最小生存的时间,单位是毫秒  -->
            <property name="minEvictableIdleTimeMillis" value="300000" />  
            <property name="validationQuery" value="SELECT ‘x‘" />  
            <property name="testWhileIdle" value="true" />  
            <property name="testOnBorrow" value="false" />  
            <property name="testOnReturn" value="false" />  
            
<!--                 打开PSCache,并且指定每个连接上PSCache的大小 -->
            <property name="poolPreparedStatements" value="true" />
            <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />  
        </bean>

此时已经可是使用此数据源了

要查看.../proname/druid/ 须web.xml中添加 servlet

<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>

此时可访问druid管理了,这里可以配置过滤,像这样:

<servlet>
    <servlet-name>DruidStatView</servlet-name>
    <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
    <init-param>
        <param-name>allow</param-name>
        <param-value></param-value>
    </init-param>
    <init-param>
        <param-name>deny</param-name>
        <param-value>192.168.146.1</param-value>
    </init-param>
    <init-param>
        <param-name>principalSessionName</param-name>
        <param-value>session.user</param-value>
    </init-param>
    <init-param>
        <param-name>principalCookieName</param-name>
        <param-value>cookies.user</param-value>
    </init-param>
</servlet>

但是现在druid 下有些标签没数据信息:web.xml下继续添加:

<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,/druid/*</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>DruidWebStatFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

到此可监控所有的请求了;

技术分享

 

发布的第一篇博客,是一个开始

欢迎指正,本人小白,口下留情,/抱拳/抱拳/抱拳

druid 使用及配置