开发者社区> 问答> 正文

druid 的spring监控无效?:配置报错 

照官方给出的,配了下spring监控
druid-stat-interceptor
在druid监控页面看了木有spring的信息,哪位试过

展开
收起
kun坤 2020-06-04 10:12:55 1209 0
1 条回答
写回答
取消 提交回答
  • 帮顶,我也遇见这个问题! ######

    <?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:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" 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.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <!-- 引入属性文件 -->
    <context:property-placeholder location="classpath*:jdbc.properties" />
    
    <!-- 配置hibernate session工厂 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    	<property name="dataSource" ref="dataSource" />
    	<property name="hibernateProperties">
    		<props>
    			<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
          	    <prop key="hibernate.hbm2ddl.auto">update</prop>
          	    <prop key="hibernate.connection.SetBigStringTryClob">true</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
    			<prop key="hibernate.use_sql_comments">true</prop>
    			<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
    		</props>
    	</property>
    
    	<!-- 自动扫描注解方式配置的hibernate类文件 -->
    	<property name="packagesToScan">
    		<list>
    			<value>cn.XXX.wx.model</value>
    		</list>
    	</property>
    </bean>
    
    
    <!-- 配置数据源 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
    	<!-- 基本属性 url、user、password -->
    	<property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    
    	<!-- 配置初始化大小、最小、最大 -->
    	<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="validationQuery" value="select 1 from dual" />
    	<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" />
    
    	<!-- 配置监控统计拦截的filters -->
    	<property name="filters" value="stat,wall" />
    </bean>
    
     
    <!-- 配置Hibernate事务管理器 -->
    <bean id="transactionManager"
    	class="org.springframework.orm.hibernate4.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory" />
    

    </bean>

    <!-- 基于注释的事务,当注释中发现@Transactional时,使用id为“transactionManager”的事务管理器  -->
    <!-- 如果没有设置transaction-manager的值,则spring以缺省默认的事务管理器来处理事务,默认事务管理器为第一个加载的事务管理器 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>
    

    <!-- 配置事务异常封装 --> <bean id="persistenceExceptionTranslationPostProcessor" class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

    <!-- 自动扫描dao和service包(自动注入) -->
    <context:component-scan base-package="cn.XXX.wx.dao,cn.XXX.wx.service" />
    
    <!-- 配置druid监控spring jdbc -->
    <bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor" />
    
    <bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">
    	<property name="patterns">
    		<list>
    			<value>cn.XXX.wx.service.*</value>
    			<value>cn.XXX.wx.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>
    
    </beans>
    

    我这样写可以的,希望能帮到你!

    2020-06-04 13:26:35
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多