fix:fix system env variable read bug.

1.12.2-2021.0.8
Haotian Zhang 2 years ago
parent 8044513e45
commit 4642f609eb

@ -28,3 +28,4 @@
- [fix:upgrade spring version.](https://github.com/Tencent/spring-cloud-tencent/pull/1086) - [fix:upgrade spring version.](https://github.com/Tencent/spring-cloud-tencent/pull/1086)
- [fix:Update README-zh.md](https://github.com/Tencent/spring-cloud-tencent/pull/1090). - [fix:Update README-zh.md](https://github.com/Tencent/spring-cloud-tencent/pull/1090).
- [feature: support Polaris configuration center extension plugin interface and support dynamic modification of log levels.](https://github.com/Tencent/spring-cloud-tencent/pull/1103). - [feature: support Polaris configuration center extension plugin interface and support dynamic modification of log levels.](https://github.com/Tencent/spring-cloud-tencent/pull/1103).
- fix:fix system env variable read bug.

@ -78,7 +78,7 @@ Spring Cloud Tencent 所有组件都已上传到 Maven 中央仓库,只需要
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-dependencies</artifactId> <artifactId>spring-cloud-tencent-dependencies</artifactId>
<!--version number--> <!--version number-->
<version>1.12.1-2021.0.8</version> <version>1.12.2-2021.0.8</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>

@ -80,7 +80,7 @@ For example:
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-dependencies</artifactId> <artifactId>spring-cloud-tencent-dependencies</artifactId>
<!--version number--> <!--version number-->
<version>1.12.1-2021.0.8</version> <version>1.12.2-2021.0.8</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>

@ -88,7 +88,7 @@
<properties> <properties>
<!-- Project revision --> <!-- Project revision -->
<revision>1.12.1-2021.0.8</revision> <revision>1.12.2-2021.0.8</revision>
<!-- Spring Framework --> <!-- Spring Framework -->
<spring.framework.version>5.3.29</spring.framework.version> <spring.framework.version>5.3.29</spring.framework.version>

@ -26,6 +26,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.tencent.cloud.polaris.config.spring.event.ConfigChangeSpringEvent; import com.tencent.cloud.polaris.config.spring.event.ConfigChangeSpringEvent;
import com.tencent.polaris.configuration.api.core.ConfigPropertyChangeInfo; import com.tencent.polaris.configuration.api.core.ConfigPropertyChangeInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
@ -37,6 +39,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import static com.tencent.cloud.polaris.config.listener.PolarisConfigListenerContext.fireConfigChange; import static com.tencent.cloud.polaris.config.listener.PolarisConfigListenerContext.fireConfigChange;
@ -50,6 +53,8 @@ import static com.tencent.cloud.polaris.config.listener.PolarisConfigListenerCon
*/ */
public final class PolarisConfigChangeEventListener implements ApplicationListener<ApplicationEvent>, ApplicationEventPublisherAware { public final class PolarisConfigChangeEventListener implements ApplicationListener<ApplicationEvent>, ApplicationEventPublisherAware {
private static final Logger LOG = LoggerFactory.getLogger(PolarisConfigChangeEventListener.class);
private static final AtomicBoolean started = new AtomicBoolean(); private static final AtomicBoolean started = new AtomicBoolean();
private ApplicationEventPublisher eventPublisher; private ApplicationEventPublisher eventPublisher;
@ -95,12 +100,23 @@ public final class PolarisConfigChangeEventListener implements ApplicationListen
Map<String, Object> ret = Maps.newHashMap(); Map<String, Object> ret = Maps.newHashMap();
MutablePropertySources sources = environment.getPropertySources(); MutablePropertySources sources = environment.getPropertySources();
sources.iterator().forEachRemaining(propertySource -> { sources.iterator().forEachRemaining(propertySource -> {
// Don't read system env variable.
if (StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME.equals(propertySource.getName())) {
return;
}
Object o = propertySource.getSource(); Object o = propertySource.getSource();
if (o instanceof Map) { if (o instanceof Map) {
for (Map.Entry<String, Object> entry : ((Map<String, Object>) o).entrySet()) { for (Map.Entry<String, Object> entry : ((Map<String, Object>) o).entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
String value = environment.getProperty(key); try {
ret.put(key, value); String value = environment.getProperty(key);
ret.put(key, value);
}
catch (Exception e) {
LOG.warn("Read property from {} with key {} failed.", propertySource.getName(), key, e);
}
} }
} }
else if (o instanceof Collection) { else if (o instanceof Collection) {

@ -70,7 +70,7 @@
</developers> </developers>
<properties> <properties>
<revision>1.12.1-2021.0.8</revision> <revision>1.12.2-2021.0.8</revision>
<!-- Dependencies --> <!-- Dependencies -->
<polaris.version>1.14.1</polaris.version> <polaris.version>1.14.1</polaris.version>

Loading…
Cancel
Save