package com.xxxxxxx.framework.datasource.druid;
import com.alibaba.druid.support.http.WebStatFilter;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
/**
* druid过滤器.
*/
@WebFilter(filterName = "druidWebStatFilter", urlPatterns = "/*", initParams = {
// 忽略资源
@WebInitParam(name = "exclusions", value = "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*") })
public class DruidStatFilter extends WebStatFilter {
}
DruidStatFilter.Java类
package com.xxxxxxx.framework.datasource.druid;
import com.alibaba.druid.support.http.StatViewServlet;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
@WebServlet(urlPatterns = "/druid/*", initParams = {
// IP白名单 (没有配置或者为空,则允许所有访问)
@WebInitParam(name = "allow", value = ""),
// IP黑名单 (存在共同时,deny优先于allow)
@WebInitParam(name = "deny", value = "192.168.1.100"),
// // 用户名
// @WebInitParam(name = "loginUsername", value = "admin"),
// // 密码
// @WebInitParam(name = "loginPassword", value = "admin"),
// 禁用HTML页面上的“Reset All”功能
@WebInitParam(name = "resetEnable", value = "false") })
@SuppressWarnings("serial")
public class DruidStatServlet extends StatViewServlet {
}
DruidStatServlet.Java类,如果需要登录时候有用户名密码,可以设置
@ServletComponentScan(basePackages ={"com.xxxxxxx.framework.datasource.druid"} )
@SpringBootApplication
@EnableEncryptableProperties
public class ApiServiceApp {
public static void main(String[] args) throws Exception {
ApplicationContext ac = SpringApplication.run(ApiServiceApp.class, args);
ProjectUtil.afterRun(ac, true, true);
}
}
最后在main启动处加扫描
@ServletComponentScan(basePackages ={"com.xxxxxxx.framework.datasource.druid"} )