Fix nacos config namespace

pull/2874/head
ruansheng 2 years ago
parent 4b24746de9
commit 1103ac3959

@ -84,6 +84,11 @@ public class NacosConfigProperties {
*/ */
public static final String SEPARATOR = "[,]"; public static final String SEPARATOR = "[,]";
/**
* Nacos default namespace .
*/
public static final String DEFAULT_NAMESPACE = "public";
private static final Pattern PATTERN = Pattern.compile("-(\\w)"); private static final Pattern PATTERN = Pattern.compile("-(\\w)");
private static final Logger log = LoggerFactory private static final Logger log = LoggerFactory
@ -560,7 +565,7 @@ public class NacosConfigProperties {
properties.put(USERNAME, Objects.toString(this.username, "")); properties.put(USERNAME, Objects.toString(this.username, ""));
properties.put(PASSWORD, Objects.toString(this.password, "")); properties.put(PASSWORD, Objects.toString(this.password, ""));
properties.put(ENCODE, Objects.toString(this.encode, "")); properties.put(ENCODE, Objects.toString(this.encode, ""));
properties.put(NAMESPACE, Objects.toString(this.namespace, "")); properties.put(NAMESPACE, this.resolveNamespace());
properties.put(ACCESS_KEY, Objects.toString(this.accessKey, "")); properties.put(ACCESS_KEY, Objects.toString(this.accessKey, ""));
properties.put(SECRET_KEY, Objects.toString(this.secretKey, "")); properties.put(SECRET_KEY, Objects.toString(this.secretKey, ""));
properties.put(RAM_ROLE_NAME, Objects.toString(this.ramRoleName, "")); properties.put(RAM_ROLE_NAME, Objects.toString(this.ramRoleName, ""));
@ -585,6 +590,16 @@ public class NacosConfigProperties {
return properties; return properties;
} }
private String resolveNamespace() {
if (DEFAULT_NAMESPACE.equals(this.namespace)) {
log.info("set nacos config namespace 'public' to ''");
return "";
}
else {
return Objects.toString(this.namespace, "");
}
}
private void enrichNacosConfigProperties(Properties nacosConfigProperties) { private void enrichNacosConfigProperties(Properties nacosConfigProperties) {
if (environment == null) { if (environment == null) {
return; return;

Loading…
Cancel
Save