|
26 | 26 | import com.google.common.collect.Maps;
|
27 | 27 | import com.tencent.cloud.polaris.config.spring.event.ConfigChangeSpringEvent;
|
28 | 28 | import com.tencent.polaris.configuration.api.core.ConfigPropertyChangeInfo;
|
| 29 | +import org.slf4j.Logger; |
| 30 | +import org.slf4j.LoggerFactory; |
29 | 31 |
|
30 | 32 | import org.springframework.boot.context.event.ApplicationStartedEvent;
|
31 | 33 | import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
|
|
37 | 39 | import org.springframework.core.env.ConfigurableEnvironment;
|
38 | 40 | import org.springframework.core.env.Environment;
|
39 | 41 | import org.springframework.core.env.MutablePropertySources;
|
| 42 | +import org.springframework.core.env.StandardEnvironment; |
40 | 43 | import org.springframework.lang.NonNull;
|
41 | 44 |
|
42 | 45 | import static com.tencent.cloud.polaris.config.listener.PolarisConfigListenerContext.fireConfigChange;
|
|
50 | 53 | */
|
51 | 54 | public final class PolarisConfigChangeEventListener implements ApplicationListener<ApplicationEvent>, ApplicationEventPublisherAware {
|
52 | 55 |
|
| 56 | + private static final Logger LOG = LoggerFactory.getLogger(PolarisConfigChangeEventListener.class); |
| 57 | + |
53 | 58 | private static final AtomicBoolean started = new AtomicBoolean();
|
54 | 59 |
|
55 | 60 | private ApplicationEventPublisher eventPublisher;
|
@@ -95,12 +100,23 @@ private Map<String, Object> loadEnvironmentProperties(ConfigurableEnvironment en
|
95 | 100 | Map<String, Object> ret = Maps.newHashMap();
|
96 | 101 | MutablePropertySources sources = environment.getPropertySources();
|
97 | 102 | 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 | + |
98 | 108 | Object o = propertySource.getSource();
|
99 | 109 | if (o instanceof Map) {
|
100 | 110 | for (Map.Entry<String, Object> entry : ((Map<String, Object>) o).entrySet()) {
|
101 | 111 | 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 | + |
104 | 120 | }
|
105 | 121 | }
|
106 | 122 | else if (o instanceof Collection) {
|
|
0 commit comments