From c8b9e590efaf5e7a10724b5f26f14de741e3c8a7 Mon Sep 17 00:00:00 2001
From: chenjialing <595168663@qq.com>
Date: Thu, 24 Feb 2022 19:02:11 +0800
Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BC=98=E5=8C=96--=E4=BC=98?=
=?UTF-8?q?=E5=8C=96=E6=9C=AC=E5=9C=B0=E7=9A=84=E6=97=A5=E5=BF=97=E8=AE=B0?=
=?UTF-8?q?=E5=BD=95=E6=96=B9=E5=BC=8F=EF=BC=8C=E5=A2=9E=E5=8A=A0druid?=
=?UTF-8?q?=E7=9A=84sql=E7=9A=84=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0?=
=?UTF-8?q?=E5=92=8C=E7=9B=91=E6=8E=A7=E9=9D=A2=E6=9D=BF=EF=BC=8C=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9druid=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=B9=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 4 +-
.../genersoft/iot/vmp/VManageBootstrap.java | 2 +
.../vmp/conf/druid/DruidConfiguration.java | 64 +++++++++++++
.../vmp/conf/druid/EnableDruidSupport.java | 24 +++++
src/main/resources/logback-spring-local.xml | 90 +++++++++++++++++++
5 files changed, 182 insertions(+), 2 deletions(-)
create mode 100644 src/main/java/com/genersoft/iot/vmp/conf/druid/DruidConfiguration.java
create mode 100644 src/main/java/com/genersoft/iot/vmp/conf/druid/EnableDruidSupport.java
create mode 100644 src/main/resources/logback-spring-local.xml
diff --git a/pom.xml b/pom.xml
index f1ac4581..809d8dbe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,8 +90,8 @@
com.alibaba
- druid
- 1.2.3
+ druid-spring-boot-starter
+ 1.1.22
diff --git a/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java b/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
index bfe58419..9dacbade 100644
--- a/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
+++ b/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp;
import java.util.logging.LogManager;
+import com.genersoft.iot.vmp.conf.druid.EnableDruidSupport;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
@@ -17,6 +18,7 @@ import springfox.documentation.oas.annotations.EnableOpenApi;
@SpringBootApplication
@EnableScheduling
@EnableOpenApi
+@EnableDruidSupport
public class VManageBootstrap extends LogManager {
private static String[] args;
private static ConfigurableApplicationContext context;
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/druid/DruidConfiguration.java b/src/main/java/com/genersoft/iot/vmp/conf/druid/DruidConfiguration.java
new file mode 100644
index 00000000..12f6e636
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/conf/druid/DruidConfiguration.java
@@ -0,0 +1,64 @@
+package com.genersoft.iot.vmp.conf.druid;
+
+import com.alibaba.druid.support.http.StatViewServlet;
+import com.alibaba.druid.support.http.WebStatFilter;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.boot.web.servlet.ServletRegistrationBean;
+import org.springframework.context.annotation.Bean;
+
+import javax.servlet.Filter;
+import javax.servlet.Servlet;
+
+/**
+ * druid监控配置
+ * @author
+ */
+public class DruidConfiguration {
+
+ @Value("${rj-druid-manage.allow:127.0.0.1}")
+ private String allow;
+
+ @Value("${rj-druid-manage.deny:}")
+ private String deny;
+
+ @Value("${rj-druid-manage.loginUsername:admin}")
+ private String loginUsername;
+
+ @Value("${rj-druid-manage.loginPassword:admin}")
+ private String loginPassword;
+
+ @Value("${rj-druid-manage.resetEnable:false}")
+ private String resetEnable;
+
+ /**
+ * druid监控页面开启
+ */
+ @Bean
+ public ServletRegistrationBean druidServlet() {
+ ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");
+ // IP白名单
+ servletRegistrationBean.addInitParameter("allow", allow);
+ // IP黑名单(共同存在时,deny优先于allow)
+ servletRegistrationBean.addInitParameter("deny", deny);
+ //控制台管理用户
+ servletRegistrationBean.addInitParameter("loginUsername", loginUsername);
+ servletRegistrationBean.addInitParameter("loginPassword", loginPassword);
+ //是否能够重置数据 禁用HTML页面上的“Reset All”功能
+ servletRegistrationBean.addInitParameter("resetEnable", resetEnable);
+ return servletRegistrationBean;
+ }
+
+ /**
+ * druid url监控配置
+ */
+ @Bean
+ public FilterRegistrationBean filterRegistrationBean() {
+ FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean<>(new WebStatFilter());
+ filterRegistrationBean.addUrlPatterns("/*");
+ filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
+ return filterRegistrationBean;
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/druid/EnableDruidSupport.java b/src/main/java/com/genersoft/iot/vmp/conf/druid/EnableDruidSupport.java
new file mode 100644
index 00000000..5fd710be
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/conf/druid/EnableDruidSupport.java
@@ -0,0 +1,24 @@
+package com.genersoft.iot.vmp.conf.druid;
+
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import org.springframework.context.annotation.Import;
+
+import java.lang.annotation.*;
+
+/**
+ * druid监控支持注解
+ *
+ * @author
+ * {@link DruidConfiguration} druid监控页面安全配置支持
+ * {@link ServletComponentScan} druid监控页面需要扫描servlet
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Inherited
+@Import({
+ DruidConfiguration.class,
+})
+@ServletComponentScan
+public @interface EnableDruidSupport {
+}
diff --git a/src/main/resources/logback-spring-local.xml b/src/main/resources/logback-spring-local.xml
new file mode 100644
index 00000000..6d818420
--- /dev/null
+++ b/src/main/resources/logback-spring-local.xml
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
+ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n
+
+
+
+
+
+
+
+
+
+ ${LOG_HOME}/wvp-%d{yyyy-MM-dd}.%i.log
+
+ 30
+ 20MB
+
+
+
+ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n
+
+
+
+
+ INFO
+
+
+
+
+
+
+
+
+ ${LOG_HOME}/error-%d{yyyy-MM-dd}.%i.log
+
+ 30
+ 20MB
+
+
+
+ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n
+
+
+
+ WARN
+
+
+
+
+
+
+
+
+
+ ${LOG_HOME}/druid-%d{yyyy-MM-dd}.%i.log
+
+ 30
+ 50MB
+
+
+
+ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file