旋转的钢笔
2019-08-10 15:33
采纳率: 19.3%
浏览 3.9k
已采纳

springboot配置完druid,spring监控没有数据?

图片说明

配置完之后,sql监控有数据,spring监控没有有数据,啥情况?

图片说明

@Configuration
public class DruidConfig {
    /**
     * 配置Druid监控
     * 后台管理Servlet
     * @return
     */
    @Bean
    public ServletRegistrationBean statViewServlet(){
        ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
        Map<String,String> initParams = new HashMap<>();
        initParams.put("loginUsername","admin");
        initParams.put("loginPassword","admin");
        //默认就是允许所有访问
        initParams.put("allow","");
        //黑名单的IP
        initParams.put("deny","192.168.15.21");
        bean.setInitParameters(initParams);
        return bean;
    }
    /**
     * 配置web监控的filter
     * @return
     */
    @Bean
    public FilterRegistrationBean webStatFilter(){
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(new WebStatFilter());
        Map<String,String> initParams = new HashMap<>();
        initParams.put("exclusions","/static/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
        bean.setInitParameters(initParams);
        bean.setUrlPatterns(Arrays.asList("/*"));
        return  bean;
    }
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 旋转的钢笔 2019-08-12 08:19
    已采纳

    可以了,原来还需要配置一个切面

    @Configuration
    public class SpringDaoMethodAspect {
    
        @Bean
        public DruidStatInterceptor druidStatInterceptor() {
            DruidStatInterceptor dsInterceptor = new DruidStatInterceptor();
            return dsInterceptor;
        }
    
        @Bean
        @Scope("prototype")
        public JdkRegexpMethodPointcut druidStatPointcut() {
            JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
            pointcut.setPattern("com.yadu.example.demo.mapper.*");
            return pointcut;
        }
    
        @Bean
        public DefaultPointcutAdvisor druidStatAdvisor(DruidStatInterceptor druidStatInterceptor, JdkRegexpMethodPointcut druidStatPointcut) {
            DefaultPointcutAdvisor defaultPointAdvisor = new DefaultPointcutAdvisor();
            defaultPointAdvisor.setPointcut(druidStatPointcut);
            defaultPointAdvisor.setAdvice(druidStatInterceptor);
            return defaultPointAdvisor;
        }
    }
    
    点赞 1 打赏 评论
  • 点赞 打赏 评论

相关推荐 更多相似问题