From 94c45f5e0f9d010065749d6b2026be423a8b7704 Mon Sep 17 00:00:00 2001 From: EightMonth Date: Mon, 8 Apr 2024 14:11:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7druid=20v1.2.22=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=85=BC=E5=AE=B9=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/config/DruidWallConfigRegister.java | 47 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 2 + 2 files changed, 49 insertions(+) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/config/DruidWallConfigRegister.java create mode 100644 jeecg-boot-base-core/src/main/resources/META-INF/spring.factories diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/config/DruidWallConfigRegister.java b/jeecg-boot-base-core/src/main/java/org/jeecg/config/DruidWallConfigRegister.java new file mode 100644 index 00000000..bcddebcd --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/config/DruidWallConfigRegister.java @@ -0,0 +1,47 @@ +package org.jeecg.config; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.SpringApplicationRunListener; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author eightmonth@qq.com + * @date 2024/4/8 11:37 + */ +public class DruidWallConfigRegister implements SpringApplicationRunListener { + + public SpringApplication application; + + private String[] args; + + + /** + * 必备,否则启动报错 + * @param application + * @param args + */ + public DruidWallConfigRegister(SpringApplication application, String[] args) { + this.application = application; + this.args = args; + } + + @Override + public void contextLoaded(ConfigurableApplicationContext context) { + ConfigurableEnvironment env = context.getEnvironment(); + Map props = new HashMap<>(); + props.put("spring.datasource.dynamic.druid.wall.selectWhereAlwayTrueCheck", false); + + MutablePropertySources propertySources = env.getPropertySources(); + + PropertySource> propertySource = new MapPropertySource("jeecg-datasource-config", props); + + propertySources.addLast(propertySource); + } +} diff --git a/jeecg-boot-base-core/src/main/resources/META-INF/spring.factories b/jeecg-boot-base-core/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..8ba71de9 --- /dev/null +++ b/jeecg-boot-base-core/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.SpringApplicationRunListener=\ +org.jeecg.config.DruidWallConfigRegister \ No newline at end of file