gaodd пре 1 година
родитељ
комит
230d8b27e9

+ 7 - 0
pom.xml

@@ -93,6 +93,13 @@
93 93
             <scope>test</scope>
94 94
         </dependency>
95 95
 
96
+         <!-- druid -->
97
+            <dependency>
98
+                <groupId>com.alibaba</groupId>
99
+                <artifactId>druid-spring-boot-starter</artifactId>
100
+                <version>1.2.9</version>
101
+            </dependency>
102
+            
96 103
         <dependency>
97 104
             <groupId>org.springframework.boot</groupId>
98 105
             <artifactId>spring-boot-starter-data-redis</artifactId>

+ 63 - 0
src/main/java/com/chinaitop/depot/DruidConfigure.java

@@ -0,0 +1,63 @@
1
+package com.chinaitop.depot;
2
+
3
+import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
4
+import com.alibaba.druid.util.Utils;
5
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
6
+import org.springframework.context.annotation.Bean;
7
+import org.springframework.context.annotation.Configuration;
8
+import javax.servlet.*;
9
+import java.io.IOException;
10
+
11
+/**
12
+ * druid配置
13
+ *
14
+ * @date 2024/06/05
15
+ **/
16
+@Configuration
17
+public class DruidConfigure {
18
+
19
+    /**
20
+     * 去除druid监控页面广告
21
+     */
22
+    @SuppressWarnings({ "rawtypes", "unchecked" })
23
+    @Bean
24
+    public FilterRegistrationBean removeDruidAdFilterRegistrationBean(DruidStatProperties properties)
25
+    {
26
+        // 获取web监控页面的参数
27
+        DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
28
+        // 提取common.js的配置路径
29
+        String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";
30
+        String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
31
+        final String filePath = "support/http/resources/js/common.js";
32
+        // 创建filter进行过滤
33
+        Filter filter = new Filter()
34
+        {
35
+            @Override
36
+            public void init(FilterConfig filterConfig) throws ServletException
37
+            {
38
+            }
39
+            @Override
40
+            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
41
+                    throws IOException, ServletException
42
+            {
43
+                chain.doFilter(request, response);
44
+                // 重置缓冲区,响应头不会被重置
45
+                response.resetBuffer();
46
+                // 获取common.js
47
+                String text = Utils.readFromResource(filePath);
48
+                // 正则替换banner, 除去底部的广告信息
49
+                text = text.replaceAll("<a.*?banner\"></a><br/>", "");
50
+                text = text.replaceAll("powered.*?shrek.wang</a>", "");
51
+                response.getWriter().write(text);
52
+            }
53
+            @Override
54
+            public void destroy()
55
+            {
56
+            }
57
+        };
58
+        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
59
+        registrationBean.setFilter(filter);
60
+        registrationBean.addUrlPatterns(commonJsPattern);
61
+        return registrationBean;
62
+    }
63
+}

+ 24 - 1
src/main/resources/application-dev.yml

@@ -1,5 +1,23 @@
1 1
 spring:
2 2
   datasource:
3
+    druid:
4
+      stat-view-servlet:
5
+        enabled: true
6
+        url-pattern: /druid/*
7
+        reset-enable: true
8
+        allow:
9
+        login-username: admin
10
+        login-password: 123456
11
+      # WebStatFilter配置
12
+      web-stat-filter:
13
+        enabled: true
14
+        url-pattern: /*
15
+        exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
16
+        session-stat-enable: false
17
+        session-stat-max-count: 1000
18
+        principal-session-name: admin
19
+        principal-cookie-name: admin
20
+        profile-enable: true
3 21
     driverClassName: com.mysql.jdbc.Driver
4 22
     url: jdbc:mysql://172.16.0.36:3306/depot_qh?useUnicode=true&characterEncoding=utf-8&useSSL=false
5 23
     username: root
@@ -52,4 +70,9 @@ KEY: 229558d3f8a9e2c67a7661a50487c790
52 70
 #webservice接口地址
53 71
 wsdlUrl: http://10.223.3.62:9025/yhzx/webServices/ExchangeServer?wsdl
54 72
 
55
-jsgjjsjUrl: http://localhost:9022/recPublish/sendMessage
73
+jsgjjsjUrl: http://localhost:9022/recPublish/sendMessage
74
+
75
+
76
+logging:
77
+  level:
78
+    com.chinaitop.depot.system.mapper: debug

+ 18 - 0
src/main/resources/application-prod.yml

@@ -1,5 +1,23 @@
1 1
 spring:
2 2
   datasource:
3
+    druid:
4
+      stat-view-servlet:
5
+        enabled: true
6
+        url-pattern: /druid/*
7
+        reset-enable: true
8
+        allow:
9
+        login-username: admin
10
+        login-password: 123456
11
+      # WebStatFilter配置
12
+      web-stat-filter:
13
+        enabled: true
14
+        url-pattern: /*
15
+        exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
16
+        session-stat-enable: false
17
+        session-stat-max-count: 1000
18
+        principal-session-name: admin
19
+        principal-cookie-name: admin
20
+        profile-enable: true
3 21
     driverClassName: com.mysql.jdbc.Driver
4 22
     url: jdbc:mysql://172.18.93.244:3306/depot_qh?useUnicode=true&characterEncoding=utf-8&useSSL=false
5 23
     username: root