druid连接池配置监控页面

jdbc.properties相关配置




# a li yun
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@39.104.20.210:1521/crcqa2
jdbc.username=crc1prod
jdbc.password=crc1prod

#websocket\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD
socket.url=/websocket
sockjs.url=/sockjs/websocket

#redis pool config
redis.pool.maxActive=200
redis.pool.maxIdle=100
redis.pool.maxWait=100
redis.pool.testOnBorrow=true

#redis config
redis.host=192.168.10.196
redis.password=123456
redis.port=6379
redis.timeout=2000
redis.dbindex=0
redis.default.expire=1800000

spring-content.xml相关配置


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-4.0.xsd">

	<context:component-scan base-package="com.bgxt">
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Service"></context:include-filter>
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>

	<task:annotation-driven scheduler="myScheduler" /><!--启用注解驱动定时任务 -->

	<task:scheduler id="myScheduler" pool-size="5" /><!--配置定时任务线程池 -->

	<context:property-placeholder
		location="classpath:jdbc.properties" />

	<util:properties id="wxProperties"
		location="classpath:/wx.properties" />

	<!--配置数据源 -->
 	<!-- <bean id="dataSources"
		class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClass}"></property>
		<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
		<property name="user" value="${jdbc.user}"></property>
		<property name="password" value="${jdbc.password}"></property>
	</bean> --> 
	
	
	<!--配置druid数据源   start-->
	<bean id="wall-filter-config" class="com.alibaba.druid.wall.WallConfig"
		init-method="init">
		<!-- 指定配置装载的目录 -->
		<property name="dir" value="META-INF/druid/wall/oracle" />
	</bean>
 
	<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
		<property name="dbType" value="mysql" />
		<property name="config" ref="wall-filter-config" />
	</bean>
	
	<bean id="dataSources" class="com.alibaba.druid.pool.DruidDataSource"
		destroy-method="close">
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="driverClassName" value="${jdbc.driver}" />
		
		 <!-- 配置初始化大小、最大、最小 --> 
		<property name="initialSize" value="1" />
        <property name="minIdle" value="1" />
        <property name="maxActive" value="20" />
		<!-- 配置获取连接等待超时的时间   -->
        <property name="maxWait" value="60000" /> 
         <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒   -->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />  
      	<!-- 配置一个连接在池中最小生存的时间,单位是毫秒   -->
        <property name="minEvictableIdleTimeMillis" value="300000" />  
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />
		<property name="poolPreparedStatements" value="true" />
		<property name="maxOpenPreparedStatements" value="20" />  
	
        <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 -->
		<property name="filters" value="stat,wall,log4j" />
		<property name="proxyFilters">
			<list>
			   <ref bean="log-filter" />
				<ref bean="wall-filter" />
				<ref bean="stat-filter" />
			</list>
		</property>
	</bean>
	
	<!-- 输出执行慢的SQL -->
	<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
		<property name="mergeSql" value="true" />
	    <property name="slowSqlMillis" value="10000" />
	    <property name="logSlowSql" value="true" />
    </bean>
	
	<!--打印log日志  -->
	<bean id="log-filter" class="com.alibaba.druid.filter.logging.Log4jFilter"/>
		
	
	<!-- druid Spring 关联监控 : 切面-->
	<bean id="druid-stat-interceptor"
			class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">
	</bean>
 	
 	<!-- 配置spring 拦截监听的包:切点 -->
	<bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut"
		scope="prototype">
		<property name="patterns">
			<list>
				<value>com.bgxt.*.dao.*</value>
				<value>com.bgxt.*.service.*</value>
			</list>
		</property>
	</bean>
	
	 <!-- 面向切面监控  advice-ref:切面  pointcut-ref:切点-->
	<aop:config>
		<aop:advisor advice-ref="druid-stat-interceptor"
			pointcut-ref="druid-stat-pointcut" />
	</aop:config>
	<!--配置数据源      end -->
	
	
	<!--配置字符编码  -->
	<bean id="restTemplate"
		class="org.springframework.web.client.RestTemplate">
		<property name="messageConverters">
			<list>
				<bean
					class="org.springframework.http.converter.StringHttpMessageConverter">
					<constructor-arg>
						<value>UTF-8</value>
					</constructor-arg>
				</bean>
				<bean
					class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
			</list>
		</property>
	</bean>

	<!--配置Session工厂 -->
	<bean id="sqlSessionFactory"
		class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSources"></property>
		<property name="configLocation"
			value="classpath:spring/mybatis-config.xml"></property>
		<!--配置自动扫描mapper文件 -->
		<property name="mapperLocations"
			value="classpath:/mappings/**/*.xml"></property>
	</bean>

	<!--配置自动扫描DAO接口,并与Mapper做关联 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.bgxt.**.dao"></property>
		<property name="sqlSessionFactoryBeanName"
			value="sqlSessionFactory"></property>
	</bean>

	<!--配置事物 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSources"></property>
	</bean>

	<!--配置声明式事物(使用声明的方式产生的事物 @transaction) 编程式事物(使用代码所编写的事物) -->
	<tx:annotation-driven
		transaction-manager="transactionManager" proxy-target-class="true" />
</beans>

web.xml 相关配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
 
 <!--加载spring上下文  -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/spring-*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <!-- 设置字符编码格式 -->
  <filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  
   <!--druid监控页面 start-->
   
   <!-- druid url monitor setting start -->
	<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>principalSessionName</param-name>
				    <param-value>USER_CACHE</param-value>
    			</init-param>
	</filter>
	<filter-mapping>
			<filter-name>DruidWebStatFilter</filter-name>
			<url-pattern>/*</url-pattern>
	</filter-mapping>
   <!-- druid url monitor setting end -->


    <!-- druid监控 -->
   <servlet>
		<servlet-name>DruidStatView</servlet-name>
		<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
		
	  <init-param>  
	   		<!--  用户名   -->
	    	 <param-name>loginUsername</param-name>  
	   		 <param-value>bgxt</param-value>  
   	  </init-param>  
      <init-param>  
		   	   <!--  密码   -->
		    	<param-name>loginPassword</param-name>  
		    	<param-value>123456</param-value>  
      </init-param> 
	</servlet>
	<servlet-mapping>
		<servlet-name>DruidStatView</servlet-name>
		<url-pattern>/druid/*</url-pattern>
	</servlet-mapping>
<!--druid监控页面   end-->
  
  <!--配置shiro权限  -->
  <filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
      <param-name>targetFilterLifecycle</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/resources/*</url-pattern>
  </servlet-mapping>
  
  
  
  <!-- springMVC核心控制器 -->
  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring/spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

以上三种配置完成后输入localhost:8080/druid/index.jsp,监控页面显示如下图:

 

参与评论 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值