Spring Boot开启Druid监控控制台

Druid监控控制台

页面:http://localhost:port/contextpath/druid/

Druid数据源控制台监控配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class DruidConfig {
@Bean
public ServletRegistrationBean druidServlet() {// 主要实现web监控的配置处理
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(
new StatViewServlet(), "/druid/*");//表示进行druid监控的配置处理操作
//servletRegistrationBean.addInitParameter("allow", "127.0.0.1,192.168.202.201");//白名单
//servletRegistrationBean.addInitParameter("deny", "192.168.202.202");//黑名单
servletRegistrationBean.addInitParameter("loginUsername", "root");//用户名
servletRegistrationBean.addInitParameter("loginPassword", "root");//密码
servletRegistrationBean.addInitParameter("resetEnable", "false");//是否可以重置数据源
return servletRegistrationBean;
}

@Bean //监控
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter());
filterRegistrationBean.addUrlPatterns("/*");//所有请求进行监控处理
filterRegistrationBean.addInitParameter("exclusions", "/static/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");//排除
return filterRegistrationBean;
}

@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource druidDataSource() {
return new DruidDataSource();
}
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2021 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :