mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
parent
85ddda03ff
commit
c348421970
@ -63,14 +63,9 @@ public class NacosConfigAutoConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
public NacosContextRefresher nacosContextRefresher(
|
public NacosContextRefresher nacosContextRefresher(
|
||||||
NacosConfigManager nacosConfigManager,
|
NacosConfigManager nacosConfigManager,
|
||||||
NacosRefreshProperties nacosRefreshProperties,
|
|
||||||
NacosRefreshHistory nacosRefreshHistory) {
|
NacosRefreshHistory nacosRefreshHistory) {
|
||||||
// Compatible with older configurations
|
// Consider that it is not necessary to be compatible with the previous configuration
|
||||||
if (nacosConfigManager.getNacosConfigProperties().isRefreshEnabled()
|
// and use the new configuration if necessary.
|
||||||
&& null != nacosRefreshProperties
|
|
||||||
&& !nacosRefreshProperties.isEnabled()) {
|
|
||||||
nacosConfigManager.getNacosConfigProperties().setRefreshEnabled(false);
|
|
||||||
}
|
|
||||||
return new NacosContextRefresher(nacosConfigManager, nacosRefreshHistory);
|
return new NacosContextRefresher(nacosConfigManager, nacosRefreshHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,10 @@ public class NacosConfigManager {
|
|||||||
if (Objects.isNull(service)) {
|
if (Objects.isNull(service)) {
|
||||||
synchronized (NacosConfigManager.class) {
|
synchronized (NacosConfigManager.class) {
|
||||||
try {
|
try {
|
||||||
service = NacosFactory.createConfigService(
|
if (Objects.isNull(service)) {
|
||||||
nacosConfigProperties.assembleConfigServiceProperties());
|
service = NacosFactory.createConfigService(
|
||||||
|
nacosConfigProperties.assembleConfigServiceProperties());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (NacosException e) {
|
catch (NacosException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
|
@ -76,7 +76,8 @@ public final class NacosPropertySourceRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getMapKey(String dataId, String group) {
|
public static String getMapKey(String dataId, String group) {
|
||||||
return String.format("%s$%s", String.valueOf(dataId), String.valueOf(group));
|
return String.join(NacosConfigProperties.COMMAS, String.valueOf(dataId),
|
||||||
|
String.valueOf(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ package com.alibaba.cloud.nacos.client;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||||
|
|
||||||
import org.springframework.core.env.MapPropertySource;
|
import org.springframework.core.env.MapPropertySource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +51,7 @@ public class NacosPropertySource extends MapPropertySource {
|
|||||||
|
|
||||||
NacosPropertySource(String group, String dataId, Map<String, Object> source,
|
NacosPropertySource(String group, String dataId, Map<String, Object> source,
|
||||||
Date timestamp, boolean isRefreshable) {
|
Date timestamp, boolean isRefreshable) {
|
||||||
super(String.format("%s#%s", dataId, group), source);
|
super(String.join(NacosConfigProperties.COMMAS, dataId, group), source);
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.dataId = dataId;
|
this.dataId = dataId;
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
|
@ -26,10 +26,15 @@ import java.util.Date;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
public class NacosRefreshHistory {
|
public class NacosRefreshHistory {
|
||||||
|
|
||||||
|
private final static Logger log = LoggerFactory.getLogger(NacosRefreshHistory.class);
|
||||||
|
|
||||||
private static final int MAX_SIZE = 20;
|
private static final int MAX_SIZE = 20;
|
||||||
|
|
||||||
private final LinkedList<Record> records = new LinkedList<>();
|
private final LinkedList<Record> records = new LinkedList<>();
|
||||||
@ -43,7 +48,8 @@ public class NacosRefreshHistory {
|
|||||||
try {
|
try {
|
||||||
md = MessageDigest.getInstance("MD5");
|
md = MessageDigest.getInstance("MD5");
|
||||||
}
|
}
|
||||||
catch (NoSuchAlgorithmException ignored) {
|
catch (NoSuchAlgorithmException e) {
|
||||||
|
log.error("failed to initialize MessageDigest : ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
{
|
{
|
||||||
"name": "spring.cloud.nacos.server-addr",
|
"name": "spring.cloud.nacos.server-addr",
|
||||||
"type": "java.lang.String",
|
"type": "java.lang.String",
|
||||||
|
"defaultValue": "localhost:8848",
|
||||||
"description": "nacos server address."
|
"description": "nacos server address."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user