mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
polish #998
This commit is contained in:
parent
0762b9fbe5
commit
327c228129
@ -18,11 +18,10 @@ package com.alibaba.cloud.nacos;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.alibaba.cloud.nacos.diagnostics.analyzer.NacosConnectionFailureException;
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@ -31,8 +30,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
*/
|
||||
public class NacosConfigManager {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(NacosConfigManager.class);
|
||||
|
||||
private static ConfigService service = null;
|
||||
|
||||
@Autowired
|
||||
@ -46,7 +43,8 @@ public class NacosConfigManager {
|
||||
properties.initConfigService(service);
|
||||
}
|
||||
catch (NacosException e) {
|
||||
log.error("create config service error!properties={},e=,", properties, e);
|
||||
throw new NacosConnectionFailureException(properties.getServerAddr(),
|
||||
e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return service;
|
||||
|
@ -78,7 +78,7 @@ public class NacosConfigProperties {
|
||||
.resolvePlaceholders("${spring.cloud.nacos.config.server-addr:}");
|
||||
if (StringUtils.isEmpty(serverAddr)) {
|
||||
serverAddr = environment
|
||||
.resolvePlaceholders("${spring.cloud.nacos.server-addr}");
|
||||
.resolvePlaceholders("${spring.cloud.nacos.server-addr:}");
|
||||
}
|
||||
this.setServerAddr(serverAddr);
|
||||
}
|
||||
|
@ -31,8 +31,10 @@ public class NacosConnectionFailureAnalyzer
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure,
|
||||
NacosConnectionFailureException cause) {
|
||||
return new FailureAnalysis("Application failed to connect to Nacos server",
|
||||
"check your Nacos server config", cause);
|
||||
return new FailureAnalysis(
|
||||
"Application failed to connect to Nacos server: \""
|
||||
+ cause.getServerAddr() + "\"",
|
||||
"Please check your Nacos server config", cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,29 +24,21 @@ package com.alibaba.cloud.nacos.diagnostics.analyzer;
|
||||
*/
|
||||
public class NacosConnectionFailureException extends RuntimeException {
|
||||
|
||||
private final String domain;
|
||||
private final String serverAddr;
|
||||
|
||||
private final String port;
|
||||
|
||||
public NacosConnectionFailureException(String domain, String port, String message) {
|
||||
public NacosConnectionFailureException(String serverAddr, String message) {
|
||||
super(message);
|
||||
this.domain = domain;
|
||||
this.port = port;
|
||||
this.serverAddr = serverAddr;
|
||||
}
|
||||
|
||||
public NacosConnectionFailureException(String domain, String port, String message,
|
||||
public NacosConnectionFailureException(String serverAddr, String message,
|
||||
Throwable cause) {
|
||||
super(message, cause);
|
||||
this.domain = domain;
|
||||
this.port = port;
|
||||
this.serverAddr = serverAddr;
|
||||
}
|
||||
|
||||
String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
String getPort() {
|
||||
return port;
|
||||
public String getServerAddr() {
|
||||
return serverAddr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -430,7 +430,8 @@ public class NacosDiscoveryProperties {
|
||||
String serverAddr = env
|
||||
.resolvePlaceholders("${spring.cloud.nacos.discovery.server-addr:}");
|
||||
if (StringUtils.isEmpty(serverAddr)) {
|
||||
serverAddr = env.resolvePlaceholders("${spring.cloud.nacos.server-addr}");
|
||||
serverAddr = env
|
||||
.resolvePlaceholders("${spring.cloud.nacos.server-addr:}");
|
||||
}
|
||||
this.setServerAddr(serverAddr);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user