Skip to content

Commit 4642f60

Browse files
committed
fix:fix system env variable read bug.
1 parent 8044513 commit 4642f60

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/1086)
2929
- [fix:Update README-zh.md](https://github.com/Tencent/spring-cloud-tencent/pull/1090).
3030
- [feature: support Polaris configuration center extension plugin interface and support dynamic modification of log levels.](https://github.com/Tencent/spring-cloud-tencent/pull/1103).
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.1-2021.0.8</version>
81+
<version>1.12.2-2021.0.8</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.1-2021.0.8</version>
83+
<version>1.12.2-2021.0.8</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.1-2021.0.8</revision>
91+
<revision>1.12.2-2021.0.8</revision>
9292

9393
<!-- Spring Framework -->
9494
<spring.framework.version>5.3.29</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;
@@ -95,12 +100,23 @@ private Map<String, Object> loadEnvironmentProperties(ConfigurableEnvironment en
95100
Map<String, Object> ret = Maps.newHashMap();
96101
MutablePropertySources sources = environment.getPropertySources();
97102
sources.iterator().forEachRemaining(propertySource -> {
103+
// Don't read system env variable.
104+
if (StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME.equals(propertySource.getName())) {
105+
return;
106+
}
107+
98108
Object o = propertySource.getSource();
99109
if (o instanceof Map) {
100110
for (Map.Entry<String, Object> entry : ((Map<String, Object>) o).entrySet()) {
101111
String key = entry.getKey();
102-
String value = environment.getProperty(key);
103-
ret.put(key, value);
112+
try {
113+
String value = environment.getProperty(key);
114+
ret.put(key, value);
115+
}
116+
catch (Exception e) {
117+
LOG.warn("Read property from {} with key {} failed.", propertySource.getName(), key, e);
118+
}
119+
104120
}
105121
}
106122
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.1-2021.0.8</revision>
73+
<revision>1.12.2-2021.0.8</revision>
7474

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

0 commit comments

Comments
 (0)