Springboot druid监控配置

时间:2023-03-10 05:03:33
Springboot druid监控配置
@Configuration
public class DataSourceConfig { @Bean
public ServletRegistrationBean statViewServlet(){
ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");
Map<String, String> initMap = new HashMap<>();
initMap.put(StatViewServlet.PARAM_NAME_JMX_USERNAME,"admin");
initMap.put(StatViewServlet.PARAM_NAME_JMX_PASSWORD,"");
initMap.put("loginUsername", "admin");
initMap.put("loginPassword", ""); bean.setInitParameters(initMap);
return bean;
} @Bean
public FilterRegistrationBean webStatFilter(){
FilterRegistrationBean bean = new FilterRegistrationBean();
bean.setFilter(new WebStatFilter());
Map<String, String> initMap = new HashMap<>();
bean.setInitParameters(initMap);
bean.setUrlPatterns(Arrays.asList("/*"));
return bean;
}
}