您好,登錄后才能下訂單哦!
根據現在的所知情況,Druid 包括3方面功能,如有缺失,請大家指正
1.作為數據庫連接池使用
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close" > <property name="driverClass" value="${jdbc.driverClass}"></property> <property name="" value="${jdbc.}"></property> <property name="url" value="${jdbc.url}"></property> <property name="username" value="${jdbc.username}"></property> <property name="password" value="${jdbc.password}"></property> <!-- 連接池最大使用連接數 --> <property name="maxActive" value="${jdbc.max.active}"></property> <!-- 初始化連接大小 --> <property name="initialSize" value="${jdbc.initial.size}"></property> <!-- 獲取連接最大等待時間 --> <property name="maxWait" value="${jdbc.max.wait}"></property> <property name="minIdle" value="${jdbc.min.idle}"></property> <!-- 自動清除無用連接 --> <property name="removeAbandoned" value="${jdbc.remove.abandoned}"></property> <!-- 清除無用連接的等待時間 --> <property name="removeAbandonedTimeout" value="${jdbc.remove.abandoned.timeout}"></property> <!-- 連接屬性 --> <property name="connectionProperties" value="clientEncoding=UTF-8"></property> <property name="testOnBorrow" value="${jdbc.testOnBorrow}"></property> <property name="validationQuery" value="${jdbc.validation.query}"></property> <property name="filters" value="stat" /> <property name="proxyFilters"> <list> <ref bean="wall-filter"/> </list> </property> </bean> <bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter"> <property name="config" ref="wall-config" /> </bean> <bean id="wall-config" class="com.alibaba.druid.wall.WallConfig"> <property name="multiStatementAllow" value="true" /> </bean> <!-- 對數據源進行事務管理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource"/>
2.提供sql執行log查詢功能
配置web.xml,至此基本配置完成,可以查看內置監控頁面了,路徑是/druid/index.html
<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>
3.采集web-jdbc關聯監控的數據
配置WebStatFilter,之后可以使用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,/druid/*</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>
修改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.company.bussines.service.*</value> <value>com.company.bussines.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>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。