提交 00bbe754 编写于 作者: lakernote's avatar lakernote

(bugfix)[整体](Druid错误discard long time none received connection)

上级 31c8be71
......@@ -18,11 +18,13 @@ import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import javax.servlet.*;
import java.io.IOException;
/**
* durid 监控页面配置 默认地址 localhost:8080/druid/login.html
*
* @author laker
*/
@Configuration
......@@ -30,6 +32,14 @@ import java.io.IOException;
public class DruidConfig {
private static final String DEFAULT_ALLOW_IP = "127.0.0.1";
/**
* 解决druid 日志报错:discard long time none received connection:xxx
*/
@PostConstruct
public void setUsePingMethod() {
System.setProperty("druid.mysql.usePingMethod", "false");
}
/**
* 参见:DruidStatViewServletConfiguration
* 黑白名单
......@@ -135,13 +145,13 @@ public class DruidConfig {
/**
* 去除底部广告
*
* @param properties
* @return
*/
@Bean
@ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true", matchIfMissing = true)
public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties)
{
public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) {
// 获取web监控页面的参数
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
// 提取common.js的配置路径
......@@ -149,16 +159,14 @@ public class DruidConfig {
String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
final String filePath = "support/http/resources/js/common.js";
// 创建filter进行过滤
Filter filter = new Filter()
{
Filter filter = new Filter() {
@Override
public void init(javax.servlet.FilterConfig filterConfig) throws ServletException
{
public void init(javax.servlet.FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
throws IOException, ServletException {
chain.doFilter(request, response);
// 重置缓冲区,响应头不会被重置
response.resetBuffer();
......@@ -169,9 +177,9 @@ public class DruidConfig {
text = text.replaceAll("powered.*?shrek.wang</a>", "");
response.getWriter().write(text);
}
@Override
public void destroy()
{
public void destroy() {
}
};
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
......
......@@ -12,8 +12,8 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
druid:
initial-size: 1
min-idle: 20
max-active: 300
min-idle: 5
max-active: 20
test-on-borrow: true
validation-query: select 1
profiles:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册