Skip to content

Commit 3fc56d4

Browse files
committed
fix:fix system env variable read bug.
1 parent e0d86bc commit 3fc56d4

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
- [fix:upgrade spring version.](https://github.com/Tencent/spring-cloud-tencent/pull/1087)
2929
- [fix:Update README-zh.md](https://github.com/Tencent/spring-cloud-tencent/pull/1093).
3030
- [feature: support Polaris configuration center extension plugin interface and support dynamic modification of log levels.](https://github.com/Tencent/spring-cloud-tencent/pull/1104).
31+
- fix:fix system env variable read bug.

README-zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Spring Cloud Tencent 所有组件都已上传到 Maven 中央仓库,只需要
7878
<groupId>com.tencent.cloud</groupId>
7979
<artifactId>spring-cloud-tencent-dependencies</artifactId>
8080
<!--version number-->
81-
<version>1.12.2-2020.0.6</version>
81+
<version>1.12.3-2020.0.6</version>
8282
<type>pom</type>
8383
<scope>import</scope>
8484
</dependency>

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ For example:
8080
<groupId>com.tencent.cloud</groupId>
8181
<artifactId>spring-cloud-tencent-dependencies</artifactId>
8282
<!--version number-->
83-
<version>1.12.2-2020.0.6</version>
83+
<version>1.12.3-2020.0.6</version>
8484
<type>pom</type>
8585
<scope>import</scope>
8686
</dependency>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888

8989
<properties>
9090
<!-- Project revision -->
91-
<revision>1.12.2-2020.0.6</revision>
91+
<revision>1.12.3-2020.0.6</revision>
9292

9393
<!-- Spring Framework -->
9494
<spring.framework.version>5.3.25</spring.framework.version>

spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigChangeEventListener.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import com.google.common.collect.Maps;
2727
import com.tencent.cloud.polaris.config.spring.event.ConfigChangeSpringEvent;
2828
import com.tencent.polaris.configuration.api.core.ConfigPropertyChangeInfo;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
2931

3032
import org.springframework.boot.context.event.ApplicationStartedEvent;
3133
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
@@ -37,6 +39,7 @@
3739
import org.springframework.core.env.ConfigurableEnvironment;
3840
import org.springframework.core.env.Environment;
3941
import org.springframework.core.env.MutablePropertySources;
42+
import org.springframework.core.env.StandardEnvironment;
4043
import org.springframework.lang.NonNull;
4144

4245
import static com.tencent.cloud.polaris.config.listener.PolarisConfigListenerContext.fireConfigChange;
@@ -50,6 +53,8 @@
5053
*/
5154
public final class PolarisConfigChangeEventListener implements ApplicationListener<ApplicationEvent>, ApplicationEventPublisherAware {
5255

56+
private static final Logger LOG = LoggerFactory.getLogger(PolarisConfigChangeEventListener.class);
57+
5358
private static final AtomicBoolean started = new AtomicBoolean();
5459

5560
private ApplicationEventPublisher eventPublisher;
@@ -96,12 +101,23 @@ private Map<String, Object> loadEnvironmentProperties(ConfigurableEnvironment en
96101
Map<String, Object> ret = Maps.newHashMap();
97102
MutablePropertySources sources = environment.getPropertySources();
98103
sources.iterator().forEachRemaining(propertySource -> {
104+
// Don't read system env variable.
105+
if (StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME.equals(propertySource.getName())) {
106+
return;
107+
}
108+
99109
Object o = propertySource.getSource();
100110
if (o instanceof Map) {
101111
for (Map.Entry<String, Object> entry : ((Map<String, Object>) o).entrySet()) {
102112
String key = entry.getKey();
103-
String value = environment.getProperty(key);
104-
ret.put(key, value);
113+
try {
114+
String value = environment.getProperty(key);
115+
ret.put(key, value);
116+
}
117+
catch (Exception e) {
118+
LOG.warn("Read property from {} with key {} failed.", propertySource.getName(), key, e);
119+
}
120+
105121
}
106122
}
107123
else if (o instanceof Collection) {

spring-cloud-tencent-dependencies/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
</developers>
7171

7272
<properties>
73-
<revision>1.12.2-2020.0.6</revision>
73+
<revision>1.12.3-2020.0.6</revision>
7474

7575
<!-- Dependencies -->
7676
<polaris.version>1.14.1</polaris.version>

0 commit comments

Comments
 (0)