Skip to content

Commit 7ad232c

Browse files
committed
fix:fix system env variable read bug.
1 parent 6874d5e commit 7ad232c

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@
2626
- fix:fix feign report -1 port bug.
2727
- fix:upgrade spring version.
2828
- fix:Update README-zh.md
29-
- feature: support Polaris configuration center extension plugin interface and support dynamic modification of log levels.
29+
- feature: support Polaris configuration center extension plugin interface and support dynamic modification of log
30+
levels.
31+
- fix:fix system env variable read bug.

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
<properties>
9191
<!-- Project revision -->
92-
<revision>1.12.1-Hoxton.SR12</revision>
92+
<revision>1.12.2-Hoxton.SR12</revision>
9393

9494
<!-- Spring Framework -->
9595
<spring.framework.version>5.2.25.RELEASE</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.1-Hoxton.SR12</revision>
73+
<revision>1.12.2-Hoxton.SR12</revision>
7474

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

0 commit comments

Comments
 (0)