Skip to content

Commit

Permalink
fix:fix system env variable read bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyeBeFreeman committed Oct 11, 2023
1 parent e0d86bc commit 3fc56d4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
- [fix:upgrade spring version.](https://github.com/Tencent/spring-cloud-tencent/pull/1087)
- [fix:Update README-zh.md](https://github.com/Tencent/spring-cloud-tencent/pull/1093).
- [feature: support Polaris configuration center extension plugin interface and support dynamic modification of log levels.](https://github.com/Tencent/spring-cloud-tencent/pull/1104).
- fix:fix system env variable read bug.
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Spring Cloud Tencent 所有组件都已上传到 Maven 中央仓库,只需要
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-dependencies</artifactId>
<!--version number-->
<version>1.12.2-2020.0.6</version>
<version>1.12.3-2020.0.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ For example:
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-dependencies</artifactId>
<!--version number-->
<version>1.12.2-2020.0.6</version>
<version>1.12.3-2020.0.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

<properties>
<!-- Project revision -->
<revision>1.12.2-2020.0.6</revision>
<revision>1.12.3-2020.0.6</revision>

<!-- Spring Framework -->
<spring.framework.version>5.3.25</spring.framework.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.google.common.collect.Maps;
import com.tencent.cloud.polaris.config.spring.event.ConfigChangeSpringEvent;
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.cloud.context.environment.EnvironmentChangeEvent;
Expand All @@ -37,6 +39,7 @@
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.lang.NonNull;

import static com.tencent.cloud.polaris.config.listener.PolarisConfigListenerContext.fireConfigChange;
Expand All @@ -50,6 +53,8 @@
*/
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 ApplicationEventPublisher eventPublisher;
Expand Down Expand Up @@ -96,12 +101,23 @@ private Map<String, Object> loadEnvironmentProperties(ConfigurableEnvironment en
Map<String, Object> ret = Maps.newHashMap();
MutablePropertySources sources = environment.getPropertySources();
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();
if (o instanceof Map) {
for (Map.Entry<String, Object> entry : ((Map<String, Object>) o).entrySet()) {
String key = entry.getKey();
String value = environment.getProperty(key);
ret.put(key, value);
try {
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) {
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-tencent-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</developers>

<properties>
<revision>1.12.2-2020.0.6</revision>
<revision>1.12.3-2020.0.6</revision>

<!-- Dependencies -->
<polaris.version>1.14.1</polaris.version>
Expand Down

0 comments on commit 3fc56d4

Please sign in to comment.