mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
fix #831
This commit is contained in:
parent
b9f70bfb8b
commit
1525b2855f
@ -30,9 +30,14 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.NacosFactory;
|
import com.alibaba.nacos.api.NacosFactory;
|
||||||
import com.alibaba.nacos.api.config.ConfigService;
|
import com.alibaba.nacos.api.config.ConfigService;
|
||||||
@ -43,6 +48,7 @@ import com.alibaba.nacos.api.config.ConfigService;
|
|||||||
* @author leijuan
|
* @author leijuan
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
* @author pbting
|
* @author pbting
|
||||||
|
* @author <a href="mailto:lyuzb@lyuzb.com">lyuzb</a>
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(NacosConfigProperties.PREFIX)
|
@ConfigurationProperties(NacosConfigProperties.PREFIX)
|
||||||
public class NacosConfigProperties {
|
public class NacosConfigProperties {
|
||||||
@ -52,6 +58,24 @@ public class NacosConfigProperties {
|
|||||||
private static final Logger log = LoggerFactory
|
private static final Logger log = LoggerFactory
|
||||||
.getLogger(NacosConfigProperties.class);
|
.getLogger(NacosConfigProperties.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
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}");
|
||||||
|
}
|
||||||
|
this.setServerAddr(serverAddr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nacos config server address.
|
* nacos config server address.
|
||||||
*/
|
*/
|
||||||
|
@ -57,6 +57,7 @@ import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
|||||||
* @author dungu.zpf
|
* @author dungu.zpf
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
|
* @author <a href="mailto:lyuzb@lyuzb.com">lyuzb</a>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ConfigurationProperties("spring.cloud.nacos.discovery")
|
@ConfigurationProperties("spring.cloud.nacos.discovery")
|
||||||
@ -64,7 +65,7 @@ public class NacosDiscoveryProperties {
|
|||||||
|
|
||||||
private static final Logger log = LoggerFactory
|
private static final Logger log = LoggerFactory
|
||||||
.getLogger(NacosDiscoveryProperties.class);
|
.getLogger(NacosDiscoveryProperties.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nacos discovery server address.
|
* nacos discovery server address.
|
||||||
*/
|
*/
|
||||||
@ -411,8 +412,11 @@ public class NacosDiscoveryProperties {
|
|||||||
public void overrideFromEnv(Environment env) {
|
public void overrideFromEnv(Environment env) {
|
||||||
|
|
||||||
if (StringUtils.isEmpty(this.getServerAddr())) {
|
if (StringUtils.isEmpty(this.getServerAddr())) {
|
||||||
this.setServerAddr(env
|
String serverAddr = env.resolvePlaceholders("${spring.cloud.nacos.discovery.server-addr:}");
|
||||||
.resolvePlaceholders("${spring.cloud.nacos.discovery.server-addr:}"));
|
if(StringUtils.isEmpty(serverAddr)) {
|
||||||
|
serverAddr = env.resolvePlaceholders("${spring.cloud.nacos.server-addr}");
|
||||||
|
}
|
||||||
|
this.setServerAddr(serverAddr);
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(this.getNamespace())) {
|
if (StringUtils.isEmpty(this.getNamespace())) {
|
||||||
this.setNamespace(env
|
this.setNamespace(env
|
||||||
|
Loading…
x
Reference in New Issue
Block a user