|
|
@ -102,87 +102,50 @@ public class NacosConfigProperties {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
@JsonIgnore
|
|
|
|
@JsonIgnore
|
|
|
|
private Environment environment;
|
|
|
|
private Environment environment;
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
|
|
|
|
public void init() {
|
|
|
|
|
|
|
|
this.overrideFromEnv();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void overrideFromEnv() {
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(this.getServerAddr())) {
|
|
|
|
|
|
|
|
String serverAddr = environment
|
|
|
|
|
|
|
|
.resolvePlaceholders("${spring.cloud.nacos.config.server-addr:}");
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(serverAddr)) {
|
|
|
|
|
|
|
|
serverAddr = environment.resolvePlaceholders(
|
|
|
|
|
|
|
|
"${spring.cloud.nacos.server-addr:localhost:8848}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setServerAddr(serverAddr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(this.getUsername())) {
|
|
|
|
|
|
|
|
this.setUsername(
|
|
|
|
|
|
|
|
environment.resolvePlaceholders("${spring.cloud.nacos.username:}"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(this.getPassword())) {
|
|
|
|
|
|
|
|
this.setPassword(
|
|
|
|
|
|
|
|
environment.resolvePlaceholders("${spring.cloud.nacos.password:}"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* nacos config server address.
|
|
|
|
* nacos config server address.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String serverAddr;
|
|
|
|
private String serverAddr;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* the nacos authentication username.
|
|
|
|
* the nacos authentication username.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String username;
|
|
|
|
private String username;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* the nacos authentication password.
|
|
|
|
* the nacos authentication password.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String password;
|
|
|
|
private String password;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* encode for nacos config content.
|
|
|
|
* encode for nacos config content.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String encode;
|
|
|
|
private String encode;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* nacos config group, group is config data meta info.
|
|
|
|
* nacos config group, group is config data meta info.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String group = "DEFAULT_GROUP";
|
|
|
|
private String group = "DEFAULT_GROUP";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* nacos config dataId prefix.
|
|
|
|
* nacos config dataId prefix.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String prefix;
|
|
|
|
private String prefix;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* the suffix of nacos config dataId, also the file extension of config content.
|
|
|
|
* the suffix of nacos config dataId, also the file extension of config content.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String fileExtension = "properties";
|
|
|
|
private String fileExtension = "properties";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* timeout for get config from nacos.
|
|
|
|
* timeout for get config from nacos.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private int timeout = 3000;
|
|
|
|
private int timeout = 3000;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* nacos maximum number of tolerable server reconnection errors.
|
|
|
|
* nacos maximum number of tolerable server reconnection errors.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String maxRetry;
|
|
|
|
private String maxRetry;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* nacos get config long poll timeout.
|
|
|
|
* nacos get config long poll timeout.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String configLongPollTimeout;
|
|
|
|
private String configLongPollTimeout;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* nacos get config failure retry time.
|
|
|
|
* nacos get config failure retry time.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String configRetryTime;
|
|
|
|
private String configRetryTime;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* If you want to pull it yourself when the program starts to get the configuration
|
|
|
|
* If you want to pull it yourself when the program starts to get the configuration
|
|
|
|
* for the first time, and the registered Listener is used for future configuration
|
|
|
|
* for the first time, and the registered Listener is used for future configuration
|
|
|
@ -191,65 +154,79 @@ public class NacosConfigProperties {
|
|
|
|
* recommend that you use {@link ConfigService#getConfigAndSignListener} directly.
|
|
|
|
* recommend that you use {@link ConfigService#getConfigAndSignListener} directly.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private boolean enableRemoteSyncConfig = false;
|
|
|
|
private boolean enableRemoteSyncConfig = false;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* endpoint for Nacos, the domain name of a service, through which the server address
|
|
|
|
* endpoint for Nacos, the domain name of a service, through which the server address
|
|
|
|
* can be dynamically obtained.
|
|
|
|
* can be dynamically obtained.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String endpoint;
|
|
|
|
private String endpoint;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* namespace, separation configuration of different environments.
|
|
|
|
* namespace, separation configuration of different environments.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String namespace;
|
|
|
|
private String namespace;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* access key for namespace.
|
|
|
|
* access key for namespace.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String accessKey;
|
|
|
|
private String accessKey;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* secret key for namespace.
|
|
|
|
* secret key for namespace.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String secretKey;
|
|
|
|
private String secretKey;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* role name for aliyun ram.
|
|
|
|
* role name for aliyun ram.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String ramRoleName;
|
|
|
|
private String ramRoleName;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* context path for nacos config server.
|
|
|
|
* context path for nacos config server.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String contextPath;
|
|
|
|
private String contextPath;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* nacos config cluster name.
|
|
|
|
* nacos config cluster name.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String clusterName;
|
|
|
|
private String clusterName;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* nacos config dataId name.
|
|
|
|
* nacos config dataId name.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String name;
|
|
|
|
private String name;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* a set of shared configurations .e.g:
|
|
|
|
* a set of shared configurations .e.g:
|
|
|
|
* spring.cloud.nacos.config.shared-configs[0]=xxx .
|
|
|
|
* spring.cloud.nacos.config.shared-configs[0]=xxx .
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private List<Config> sharedConfigs;
|
|
|
|
private List<Config> sharedConfigs;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* a set of extensional configurations .e.g:
|
|
|
|
* a set of extensional configurations .e.g:
|
|
|
|
* spring.cloud.nacos.config.extension-configs[0]=xxx .
|
|
|
|
* spring.cloud.nacos.config.extension-configs[0]=xxx .
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private List<Config> extensionConfigs;
|
|
|
|
private List<Config> extensionConfigs;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* the master switch for refresh configuration, it default opened(true).
|
|
|
|
* the master switch for refresh configuration, it default opened(true).
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private boolean refreshEnabled = true;
|
|
|
|
private boolean refreshEnabled = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
|
|
|
|
public void init() {
|
|
|
|
|
|
|
|
this.overrideFromEnv();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void overrideFromEnv() {
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(this.getServerAddr())) {
|
|
|
|
|
|
|
|
String serverAddr = environment
|
|
|
|
|
|
|
|
.resolvePlaceholders("${spring.cloud.nacos.config.server-addr:}");
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(serverAddr)) {
|
|
|
|
|
|
|
|
serverAddr = environment.resolvePlaceholders(
|
|
|
|
|
|
|
|
"${spring.cloud.nacos.server-addr:localhost:8848}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setServerAddr(serverAddr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(this.getUsername())) {
|
|
|
|
|
|
|
|
this.setUsername(
|
|
|
|
|
|
|
|
environment.resolvePlaceholders("${spring.cloud.nacos.username:}"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(this.getPassword())) {
|
|
|
|
|
|
|
|
this.setPassword(
|
|
|
|
|
|
|
|
environment.resolvePlaceholders("${spring.cloud.nacos.password:}"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// todo sts support
|
|
|
|
// todo sts support
|
|
|
|
|
|
|
|
|
|
|
|
public String getServerAddr() {
|
|
|
|
public String getServerAddr() {
|
|
|
@ -566,7 +543,7 @@ public class NacosConfigProperties {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Properties assembleConfigServiceProperties() {
|
|
|
|
public Properties assembleConfigServiceProperties() {
|
|
|
|
Properties properties = new Properties();
|
|
|
|
Properties properties = new Properties();
|
|
|
|
properties.put(SERVER_ADDR, Objects.toString(this.serverAddr, DEFAULT_ADDRESS));
|
|
|
|
properties.put(SERVER_ADDR, Objects.toString(this.serverAddr, ""));
|
|
|
|
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, ""));
|
|
|
@ -592,6 +569,12 @@ public class NacosConfigProperties {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enrichNacosConfigProperties(properties);
|
|
|
|
enrichNacosConfigProperties(properties);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set default value when serverAddr and endpoint is empty
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(this.serverAddr) && StringUtils.isEmpty(this.endpoint)) {
|
|
|
|
|
|
|
|
properties.put(SERVER_ADDR, DEFAULT_ADDRESS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return properties;
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|