mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Prevent non-refreshing configurations from retrieving the latest configuration values when refreshing
This commit is contained in:
parent
c1afd3974d
commit
f2a9e60a9e
@ -16,24 +16,21 @@
|
||||
|
||||
package org.springframework.cloud.alibaba.nacos;
|
||||
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.*;
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.*;
|
||||
|
||||
/**
|
||||
* nacos properties
|
||||
@ -110,7 +107,6 @@ public class NacosConfigProperties {
|
||||
*/
|
||||
private String clusterName;
|
||||
|
||||
@Value("${spring.application.name}")
|
||||
private String name;
|
||||
|
||||
private String[] activeProfiles;
|
||||
@ -271,6 +267,10 @@ public class NacosConfigProperties {
|
||||
this.extConfig = extConfig;
|
||||
}
|
||||
|
||||
public void setActiveProfiles(String[] activeProfiles) {
|
||||
this.activeProfiles = activeProfiles;
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
/**
|
||||
* the data id of extended configuration
|
||||
@ -348,4 +348,5 @@ public class NacosConfigProperties {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -78,6 +78,13 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
dataIdPrefix = name;
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(dataIdPrefix)) {
|
||||
dataIdPrefix = env.getProperty("spring.application.name");
|
||||
}
|
||||
|
||||
List<String> profiles = Arrays.asList(env.getActiveProfiles());
|
||||
nacosConfigProperties.setActiveProfiles(profiles.toArray(new String[0]));
|
||||
|
||||
String fileExtension = nacosConfigProperties.getFileExtension();
|
||||
|
||||
CompositePropertySource composite = new CompositePropertySource(
|
||||
|
@ -108,6 +108,7 @@ public class NacosContextRefresher
|
||||
Listener listener = listenerMap.computeIfAbsent(dataId, i -> new Listener() {
|
||||
@Override
|
||||
public void receiveConfigInfo(String configInfo) {
|
||||
loadCount.incrementAndGet();
|
||||
String md5 = "";
|
||||
if (!StringUtils.isEmpty(configInfo)) {
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user