@Controller
public class DruidConfig {
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource druidDataSource(){
return new DruidDataSource();
}
//后台监控功能
@Bean
public ServletRegistrationBean statViewServlet(){
ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");
HashMap<String, String> stringStringHashMap = new HashMap<>();
//增加配置
stringStringHashMap.put("loginUsername","admin"); //登录的key是固定的
stringStringHashMap.put("loginPassword","123456");
//允许谁可以访问
stringStringHashMap.put("allow","");
//后台需要有人登录,账号密码
bean.setInitParameters(stringStringHashMap);
return bean;
}
//filter
@Bean
public FilterRegistrationBean webStatFilter(){
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
bean.setFilter(new WebStatFilter());
//可以过滤哪些请求呢?
Map<String, String> initParameters=new HashMap<>();
bean.setInitParameters(initParameters);
//这些东西不进行统计
initParameters.put("exclusions","*.js,*.css,/druid/*");
return bean;
}
}