From 9253613440eb7be4c3a81e0491f9ef52b4fc618c Mon Sep 17 00:00:00 2001 From: KingStar Date: Fri, 18 Mar 2022 12:21:03 +0000 Subject: [PATCH] =?UTF-8?q?!61=20update=203.0.0=20*=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=8F=AF=E8=8E=B7=E5=8F=96=E4=B8=BB=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=B9=E5=BC=8F=20*=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=82=E5=B8=B8=E6=89=93=E5=8D=B0=20*=20Me?= =?UTF-8?q?rge=20remote-tracking=20branch=20'origin/3.0.0'=20into=203.0.0?= =?UTF-8?q?=20*=20=E4=BF=AE=E5=A4=8D=E6=8F=92=E4=BB=B6=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=BB=E7=A8=8B=E5=BA=8F=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 139 +++++++++++++++++ .../bootstrap/ConfigurePluginEnvironment.java | 4 +- .../EmptyMainApplicationContext.java | 6 + .../processor/FrameDefineBeanProcessor.java | 9 ++ .../DefaultMainEnvironmentProvider.java | 123 +++++++++++++++ .../realize/EmptyMainEnvironmentProvider.java | 68 +++++++++ .../realize/MainEnvironmentProvider.java | 84 ++++++++++ springboot-plugin-framework/pom.xml | 144 +----------------- .../starblues/core/DefaultPluginManager.java | 1 + .../starblues/core/PluginLauncherManager.java | 4 +- .../launcher/plugin/PluginMethodRunner.java | 10 +- .../spring/MainApplicationContext.java | 9 ++ .../spring/MainApplicationContextProxy.java | 45 +++++- 13 files changed, 493 insertions(+), 153 deletions(-) create mode 100644 springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/DefaultMainEnvironmentProvider.java create mode 100644 springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/EmptyMainEnvironmentProvider.java create mode 100644 springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/MainEnvironmentProvider.java diff --git a/pom.xml b/pom.xml index 5df6ef7..23ca7cd 100644 --- a/pom.xml +++ b/pom.xml @@ -29,8 +29,49 @@ 1.8 UTF-8 3.8.1 + + 3.1.0 + 3.1.0 + 3.1.0 + 1.6 + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + https://gitee.com/starblues/springboot-plugin-framework-parent + scm:https://gitee.com/starblues/springboot-plugin-framework-parent.git + scm:https://gitee.com/starblues/springboot-plugin-framework-parent.git + 1.0 + + + + + sonatype-nexus-snapshots + oss Snapshots Repository + https://oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-staging + oss Staging Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + StarBlues + starblues@foxmail.com + https://gitee.com/starblues/ + + + @@ -42,8 +83,106 @@ ${java.version} + + + org.apache.maven.plugins + maven-assembly-plugin + ${maven-assembly-plugin.version} + + + jar-with-dependencies + + ${project.artifactId}-${project.version} + false + false + + + true + true + + + + + + make-assembly + package + + single + + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + package + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + ${plugin.skip} + + + + package + + jar + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + ${plugin.skip} + + + + sign-artifacts + verify + + sign + + + + + + + dev + + true + + + true + + + + + release + + false + + + + + \ No newline at end of file diff --git a/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java index ea0bae3..c159c6e 100644 --- a/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java +++ b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java @@ -73,8 +73,8 @@ class ConfigurePluginEnvironment { env.put(SPRING_JMX_UNIQUE_NAMES, true); env.put(SPRING_ADMIN_JMX_NAME, SPRING_ADMIN_JMX_VALUE + pluginId); env.put(REGISTER_SHUTDOWN_HOOK_PROPERTY, false); - env.put(MBEAN_DOMAIN_PROPERTY_NAME, null); - environment.getPropertySources().addLast(new MapPropertySource(PLUGIN_PROPERTY_NAME, env)); + env.put(MBEAN_DOMAIN_PROPERTY_NAME, pluginId); + environment.getPropertySources().addFirst(new MapPropertySource(PLUGIN_PROPERTY_NAME, env)); if(processorContext.runMode() == ProcessorContext.RunMode.ONESELF){ ConfigureMainPluginEnvironment configureMainPluginEnvironment = diff --git a/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/EmptyMainApplicationContext.java b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/EmptyMainApplicationContext.java index 7b67746..53a5536 100644 --- a/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/EmptyMainApplicationContext.java +++ b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/EmptyMainApplicationContext.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.ObjectProvider; import org.springframework.core.ResolvableType; import java.lang.annotation.Annotation; +import java.util.Collections; import java.util.Map; import java.util.Set; @@ -45,4 +46,9 @@ public class EmptyMainApplicationContext implements MainApplicationContext { public void close() throws Exception { } + + @Override + public Map> getConfigurableEnvironment() { + return Collections.emptyMap(); + } } diff --git a/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/FrameDefineBeanProcessor.java b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/FrameDefineBeanProcessor.java index b4c6549..56fcb6a 100644 --- a/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/FrameDefineBeanProcessor.java +++ b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/FrameDefineBeanProcessor.java @@ -17,6 +17,9 @@ package com.gitee.starblues.bootstrap.processor; +import com.gitee.starblues.bootstrap.realize.DefaultMainEnvironmentProvider; +import com.gitee.starblues.bootstrap.realize.EmptyMainEnvironmentProvider; +import com.gitee.starblues.bootstrap.realize.MainEnvironmentProvider; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.integration.AutoIntegrationConfiguration; import com.gitee.starblues.integration.ExtendPointConfiguration; @@ -36,11 +39,17 @@ public class FrameDefineBeanProcessor implements SpringPluginProcessor { InsidePluginDescriptor pluginDescriptor = context.getPluginDescriptor(); ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory(); beanFactory.registerSingleton("pluginDescriptor", pluginDescriptor.toPluginDescriptor()); + beanFactory.registerSingleton("mainApplicationContext", context.getMainApplicationContext()); + MainEnvironmentProvider mainEnvironmentProvider = null; if(context.runMode() == ProcessorContext.RunMode.ONESELF){ beanFactory.registerSingleton("integrationConfiguration", new AutoIntegrationConfiguration()); applicationContext.registerBean(ExtendPointConfiguration.class); + mainEnvironmentProvider = new EmptyMainEnvironmentProvider(); + } else { + mainEnvironmentProvider = new DefaultMainEnvironmentProvider(context.getMainApplicationContext()); } + beanFactory.registerSingleton("mainEnvironmentProvider", mainEnvironmentProvider); } @Override diff --git a/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/DefaultMainEnvironmentProvider.java b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/DefaultMainEnvironmentProvider.java new file mode 100644 index 0000000..8487d36 --- /dev/null +++ b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/DefaultMainEnvironmentProvider.java @@ -0,0 +1,123 @@ +/** + * Copyright [2019-2022] [starBlues] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.gitee.starblues.bootstrap.realize; + +import com.gitee.starblues.loader.utils.ObjectUtils; +import com.gitee.starblues.spring.MainApplicationContext; + +import java.util.Map; +import java.util.function.Function; + +/** + * 主程序配置信息提供者默认实现 + * + * @author starBlues + * @version 3.0.0 + */ +public class DefaultMainEnvironmentProvider implements MainEnvironmentProvider{ + + private final MainApplicationContext mainApplicationContext; + + public DefaultMainEnvironmentProvider(MainApplicationContext mainApplicationContext) { + this.mainApplicationContext = mainApplicationContext; + } + + @Override + public Object getValue(String name) { + Map> configurableEnvironment = mainApplicationContext.getConfigurableEnvironment(); + if(ObjectUtils.isEmpty(configurableEnvironment)){ + return null; + } + for (Map.Entry> entry : configurableEnvironment.entrySet()) { + Map value = entry.getValue(); + Object o = value.get(name); + if(o != null){ + return o; + } + } + return null; + } + + @Override + public String getString(String name) { + return getValue(name, String::valueOf); + } + + @Override + public Integer getInteger(String name) { + return getValue(name, value -> { + if(value instanceof Integer){ + return (Integer) value; + } + return Integer.parseInt(String.valueOf(value)); + }); + } + + @Override + public Long getLong(String name) { + return getValue(name, value -> { + if(value instanceof Long){ + return (Long) value; + } + return Long.parseLong(String.valueOf(value)); + }); + } + + @Override + public Double getDouble(String name) { + return getValue(name, value -> { + if(value instanceof Double){ + return (Double) value; + } + return Double.parseDouble(String.valueOf(value)); + }); + } + + @Override + public Float getFloat(String name) { + return getValue(name, value -> { + if(value instanceof Float){ + return (Float) value; + } + return Float.parseFloat(String.valueOf(value)); + }); + } + + @Override + public Boolean getBoolean(String name) { + return getValue(name, value -> { + if(value instanceof Boolean){ + return (Boolean) value; + } + return Boolean.parseBoolean(String.valueOf(value)); + }); + } + + @Override + public Map> getAll() { + return mainApplicationContext.getConfigurableEnvironment(); + } + + private T getValue(String name, Function function){ + Object value = getValue(name); + if(value == null){ + return null; + } + return function.apply(value); + } + +} diff --git a/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/EmptyMainEnvironmentProvider.java b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/EmptyMainEnvironmentProvider.java new file mode 100644 index 0000000..8180226 --- /dev/null +++ b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/EmptyMainEnvironmentProvider.java @@ -0,0 +1,68 @@ +/** + * Copyright [2019-2022] [starBlues] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.gitee.starblues.bootstrap.realize; + +import java.util.Collections; +import java.util.Map; + +/** + * 主程序配置信息提供者空值实现 + * + * @author starBlues + * @version 3.0.0 + */ +public class EmptyMainEnvironmentProvider implements MainEnvironmentProvider{ + @Override + public Object getValue(String name) { + return null; + } + + @Override + public String getString(String name) { + return null; + } + + @Override + public Integer getInteger(String name) { + return null; + } + + @Override + public Long getLong(String name) { + return null; + } + + @Override + public Double getDouble(String name) { + return null; + } + + @Override + public Float getFloat(String name) { + return null; + } + + @Override + public Boolean getBoolean(String name) { + return null; + } + + @Override + public Map> getAll() { + return Collections.emptyMap(); + } +} diff --git a/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/MainEnvironmentProvider.java b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/MainEnvironmentProvider.java new file mode 100644 index 0000000..ea68a16 --- /dev/null +++ b/springboot-plugin-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/MainEnvironmentProvider.java @@ -0,0 +1,84 @@ +/** + * Copyright [2019-2022] [starBlues] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.gitee.starblues.bootstrap.realize; + +import java.util.Map; + +/** + * 主程序配置信息提供者 + * + * @author starBlues + * @version 3.0.0 + */ +public interface MainEnvironmentProvider { + + /** + * 根据名称获取配置值 + * @param name 配置名称 + * @return 配置值 + */ + Object getValue(String name); + + /** + * 根据名称获取 String 类型配置值 + * @param name 配置名称 + * @return 配置值 + */ + String getString(String name); + + /** + * 根据名称获取 Integer 类型配置值 + * @param name 配置名称 + * @return 配置值 + */ + Integer getInteger(String name); + + /** + * 根据名称获取 Long 类型配置值 + * @param name 配置名称 + * @return 配置值 + */ + Long getLong(String name); + + /** + * 根据名称获取 Double 类型配置值 + * @param name 配置名称 + * @return 配置值 + */ + Double getDouble(String name); + + /** + * 根据名称获取 Float 类型配置值 + * @param name 配置名称 + * @return 配置值 + */ + Float getFloat(String name); + + /** + * 根据名称获取 Boolean 类型配置值 + * @param name 配置名称 + * @return 配置值 + */ + Boolean getBoolean(String name); + + /** + * 获取所有配置集合 + * @return Map + */ + Map> getAll(); + +} diff --git a/springboot-plugin-framework/pom.xml b/springboot-plugin-framework/pom.xml index 4c832fe..a5ad6f0 100644 --- a/springboot-plugin-framework/pom.xml +++ b/springboot-plugin-framework/pom.xml @@ -16,55 +16,14 @@ spring boot 插件式开发集成包 - - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - https://gitee.com/starblues/springboot-plugin-framework-parent - scm:https://gitee.com/starblues/springboot-plugin-framework-parent.git - scm:https://gitee.com/starblues/springboot-plugin-framework-parent.git - 1.0 - - - - - sonatype-nexus-snapshots - oss Snapshots Repository - https://oss.sonatype.org/content/repositories/snapshots - - - sonatype-nexus-staging - oss Staging Repository - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - - StarBlues - starblues@foxmail.com - https://gitee.com/starblues/ - - - - 3.1.0 - 3.1.0 - 3.1.0 - 1.6 - 2.10.1 1.7.7 2.11.0 5.3.12 2.5.6 + 3.0.12.RELEASE 2.10.5 1.5.2 4.0.1 @@ -116,7 +75,7 @@ org.thymeleaf thymeleaf-spring5 - 3.0.12.RELEASE + ${thymeleaf-spring5.version} provided true @@ -156,7 +115,6 @@ - @@ -178,105 +136,7 @@ - - - org.apache.maven.plugins - maven-assembly-plugin - ${maven-assembly-plugin.version} - - - jar-with-dependencies - - ${project.artifactId}-${project.version} - false - false - - - true - true - - - - - - make-assembly - package - - single - - - - - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - package - - jar-no-fork - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - ${plugin.skip} - - - - package - - jar - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - ${plugin.skip} - - - - sign-artifacts - verify - - sign - - - - - - - dev - - true - - - true - - - - - release - - false - - - - - \ No newline at end of file diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/DefaultPluginManager.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/DefaultPluginManager.java index 580378e..50b3e55 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/DefaultPluginManager.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/DefaultPluginManager.java @@ -131,6 +131,7 @@ public class DefaultPluginManager implements PluginManager{ warn.append(i + 1).append(". ").append(pluginRootDirs.get(i)).append("\n"); } warn.append("请检查路径是否合适.\n"); + warn.append("请检查配置[plugin.runMode]是否合适.\n"); if(provider.getRuntimeMode() == RuntimeMode.DEV){ warn.append("请检查插件包是否编译.\n"); } else { diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/PluginLauncherManager.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/PluginLauncherManager.java index d825433..432fcf6 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/PluginLauncherManager.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/PluginLauncherManager.java @@ -60,9 +60,7 @@ public class PluginLauncherManager extends DefaultPluginManager{ GenericApplicationContext applicationContext, IntegrationConfiguration configuration) { super(realizeProvider, configuration); - this.mainApplicationContext = new MainApplicationContextProxy( - applicationContext.getBeanFactory(), - applicationContext); + this.mainApplicationContext = new MainApplicationContextProxy(applicationContext, applicationContext); this.mainGenericApplicationContext = applicationContext; this.configuration = configuration; this.invokeSupperCache = new DefaultInvokeSupperCache(); diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginMethodRunner.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginMethodRunner.java index 9515cdf..c5d12d4 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginMethodRunner.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginMethodRunner.java @@ -79,8 +79,14 @@ public class PluginMethodRunner extends MethodRunner { } catch (Exception e){ String error = "Invoke failure: " + ReflectionUtils.methodToString(runClass, runMethodName, runMethod.getParameterTypes()) - + ". " + e.getMessage(); - logger.error(error, e); + + ". "; + String message = e.getMessage(); + if(message != null){ + error = error + message; + logger.error(error, e); + } else { + logger.error(error); + } throw new Exception(error); } } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/spring/MainApplicationContext.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/spring/MainApplicationContext.java index 9e4f1a4..070e04a 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/spring/MainApplicationContext.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/spring/MainApplicationContext.java @@ -16,6 +16,8 @@ package com.gitee.starblues.spring; +import java.util.Map; + /** * 主程序 ApplicationContext 接口 * @author starBlues @@ -23,4 +25,11 @@ package com.gitee.starblues.spring; */ public interface MainApplicationContext extends ApplicationContext { + /** + * 得到主程序所有配置的 env + * + * @return 主程序配置的 env 集合 + */ + Map> getConfigurableEnvironment(); + } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/spring/MainApplicationContextProxy.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/spring/MainApplicationContextProxy.java index 11dfb18..a430ae8 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/spring/MainApplicationContextProxy.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/spring/MainApplicationContextProxy.java @@ -16,6 +16,17 @@ package com.gitee.starblues.spring; +import org.springframework.context.support.GenericApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; + /** * 主程序 ApplicationContext 的实现 * @author starBlues @@ -23,11 +34,37 @@ package com.gitee.starblues.spring; */ public class MainApplicationContextProxy extends ApplicationContextProxy implements MainApplicationContext{ - public MainApplicationContextProxy(Object targetBeanFactory) { - super(targetBeanFactory); + private final GenericApplicationContext applicationContext; + + public MainApplicationContextProxy(GenericApplicationContext applicationContext) { + super(applicationContext.getBeanFactory()); + this.applicationContext = applicationContext; + } + + public MainApplicationContextProxy(GenericApplicationContext applicationContext, AutoCloseable autoCloseable) { + super(applicationContext.getBeanFactory(), autoCloseable); + this.applicationContext = applicationContext; } - public MainApplicationContextProxy(Object targetBeanFactory, AutoCloseable autoCloseable) { - super(targetBeanFactory, autoCloseable); + @Override + public Map> getConfigurableEnvironment() { + ConfigurableEnvironment environment = applicationContext.getEnvironment(); + MutablePropertySources propertySources = environment.getPropertySources(); + Map> environmentMap = new LinkedHashMap<>(propertySources.size()); + for (PropertySource propertySource : propertySources) { + if (!(propertySource instanceof EnumerablePropertySource)) { + continue; + } + EnumerablePropertySource enumerablePropertySource = (EnumerablePropertySource) propertySource; + String[] propertyNames = enumerablePropertySource.getPropertyNames(); + Map values = new HashMap<>(propertyNames.length); + for (String propertyName : propertyNames) { + values.put(propertyName, enumerablePropertySource.getProperty(propertyName)); + } + if (!values.isEmpty()) { + environmentMap.put(propertySource.getName(), values); + } + } + return environmentMap; } } -- Gitee