Druid配置数据源监控

Druid配置数据源监控:

1、在web.xml中引入druid filter 和servlet

 

<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>/css/*,/jslib/*,*.js,*.css,/druid*,*.jsp</param-value>
	  </init-param>
</filter>

<filter-mapping>
		<filter-name>druidWebStatFilter</filter-name>
		<url-pattern>/*</url-pattern>
</filter-mapping>

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

 

2、在Spring.xml中配置监控Service层

<!-- 配置druid监控spring jdbc -->
<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.current.service.*</value>
		</list>
	</property>
</bean>
<aop:config>
<aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut" />
</aop:config>

 

3、这样就可以直接请求 /项目路径/druid/index.html

或者调用action 返回index.html

@Namespace("/")
@Action(value="duridAction",results={@Result(name="druid",location="/druid/index.html",type="redirect")})
public class DruidControl extends BaseAction{
	
	private static final long serialVersionUID = 1L;
	/**
	 * 跳转到连接池监控页面
	 * @return
	 */
	public String druid(){
		return "druid";
	}
}

 

4、这样在菜单上点击菜单的时候就可以把/druid/index.html引入进来了。

需要注意的是,如果是用了js框架的href方式,/druid/index.html中包含的js文件是不会运行的,这里需要用iframe的方式引入:

addTab({
		title : node.text,
		closable : true,
		iconCls : node.iconCls,
		content : '<iframe src="' + url + '" frameborder="0" style="border:0;width:100%;height:99%;"></iframe>'
});

 

如图所示:


Druid配置数据源监控_第1张图片
 

 

 

你可能感兴趣的:(druid)