您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
根据现在的所知情况,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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。