qa-prevention-gwj/src/main/java/com/zcloud/DruidConfiguration.java

46 lines
1.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.zcloud;
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;
/**
* 说明druid数据库连接池的配置类(必须与启动类包目录同级)
* 作者luoxiaobao
* 官网www.qdkjchina.com
*/
@Configuration
public class DruidConfiguration {
@Bean
public ServletRegistrationBean<StatViewServlet> statViewServlet() {
// 创建servlet注册实体
ServletRegistrationBean<StatViewServlet> servletRegistrationBean = new ServletRegistrationBean<StatViewServlet>(new StatViewServlet(), "/druid/*");
// 设置ip白名单
//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,*.json,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
return filterRegistrationBean;
}
}