1.配置yml
1 spring: 2 datasource: 3 # 数据源基本配置 4 username: song 5 password: 123456 6 driver-class-name: com.mysql.jdbc.Driver 7 url: jdbc:mysql://39.106.222.34:3306/mybatis 8 type: com.alibaba.druid.pool.DruidDataSource 9 # 数据源其他配置 10 initialSize: 5 11 minIdle: 5 12 maxActive: 20 13 maxWait: 60000 14 timeBetweenEvictionRunsMillis: 60000 15 minEvictableIdleTimeMillis: 300000 16 validationQuery: SELECT 1 FROM DUAL 17 testWhileIdle: true 18 testOnBorrow: false 19 testOnReturn: false 20 poolPreparedStatements: true 21 # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,‘wall‘用于防火墙 22 filters: stat,wall,log4j 23 maxPoolPreparedStatementPerConnectionSize: 20 24 useGlobalDataSourceStat: true 25 connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
2.java 代码
@Configuration public class DruidConfiguration { @Bean public ServletRegistrationBean statViewServle(){ ServletRegistrationBean servletRegistrationBean=new ServletRegistrationBean(new StatViewServlet(),"/druid/*"); //IP白名单 //servletRegistrationBean.addInitParameter("allow","192.168.1.12,127.0.0.1"); //IP黑名单 //servletRegistrationBean.addInitParameter("deny","192.168.4.23"); //控制台用户 servletRegistrationBean.addInitParameter("loginUsername","admin"); servletRegistrationBean.addInitParameter("loginPassword","123456"); //是否能够重置数据 servletRegistrationBean.addInitParameter("resetEnable","false"); return servletRegistrationBean; } @Bean public FilterRegistrationBean statFilter(){ FilterRegistrationBean filterRegistrationBean=new FilterRegistrationBean(new WebStatFilter()); //添加过滤规则 filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); return filterRegistrationBean; } }
3。访问监控 http://localhost/druid/weburi.html
输入java代码里配置的用户名和密码
原文地址:https://www.cnblogs.com/lijiasnong/p/9889510.html
时间: 2024-10-07 14:38:45