package org.fh;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
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;
@Configuration
public class DruidConfiguration {
@Bean
public ServletRegistrationBean<StatViewServlet> statViewServlet() {
ServletRegistrationBean<StatViewServlet> servletRegistrationBean = new ServletRegistrationBean<StatViewServlet>(new StatViewServlet(), "/druid/*");
//servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
// 設定ip黑名單,如果allow與deny共同存在時,deny優先於allow
//servletRegistrationBean.addInitParameter("deny", "192.168.0.1");
// 設定控制檯管理使用者
//servletRegistrationBean.addInitParameter("loginUsername", "druid");
//servletRegistrationBean.addInitParameter("loginPassword", "fhadmin");
// 是否可以重置資料
servletRegistrationBean.addInitParameter("resetEnable", "false");
return servletRegistrationBean;
}
@Bean
public FilterRegistrationBean<WebStatFilter> statFilter() {
// 建立過濾器
FilterRegistrationBean<WebStatFilter> filterRegistrationBean = new FilterRegistrationBean<WebStatFilter>(new WebStatFilter());
// 設定過濾器過濾路徑
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
return filterRegistrationBean;
}
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結