apbbbbb
旋转的钢笔
采纳率19.3%
2019-08-10 15:33

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条回答

  • apbbbbb 旋转的钢笔 2年前

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

    @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;
        }
    }
    
    点赞 评论 复制链接分享
  • dashicaineng 蔡能教授,网站特聘专家 2年前