|
|
|
@ -21,8 +21,6 @@ import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
|
|
|
|
import com.tencent.cloud.common.constant.ContextConstant.ModifierOrder;
|
|
|
|
|
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
|
|
|
|
|
import com.tencent.polaris.api.config.plugin.DefaultPlugins;
|
|
|
|
@ -38,7 +36,6 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -46,19 +43,9 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
*
|
|
|
|
|
* @author Haotian Zhang
|
|
|
|
|
*/
|
|
|
|
|
@ConfigurationProperties("spring.cloud.consul.discovery")
|
|
|
|
|
@ConfigurationProperties("spring.cloud.consul")
|
|
|
|
|
public class ConsulContextProperties {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private Environment environment;
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
|
public void init() {
|
|
|
|
|
if (StringUtils.isEmpty(serviceName)) {
|
|
|
|
|
serviceName = environment.getProperty("spring.application.name");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Host of consul(or consul agent).
|
|
|
|
|
*/
|
|
|
|
@ -68,17 +55,22 @@ public class ConsulContextProperties {
|
|
|
|
|
|
|
|
|
|
private boolean enabled = false;
|
|
|
|
|
|
|
|
|
|
private boolean register = true;
|
|
|
|
|
@Value("${spring.cloud.consul.discovery.register:#{'true'}}")
|
|
|
|
|
private boolean register;
|
|
|
|
|
|
|
|
|
|
@Value("${spring.cloud.consul.discovery.discovery-enabled:${spring.cloud.consul.discovery.enabled:#{true}}}")
|
|
|
|
|
@Value("${spring.cloud.consul.discovery.enabled:#{'true'}}")
|
|
|
|
|
private boolean discoveryEnabled;
|
|
|
|
|
|
|
|
|
|
@Value("${spring.cloud.consul.discovery.instance-id:}")
|
|
|
|
|
private String instanceId;
|
|
|
|
|
|
|
|
|
|
@Value("${spring.cloud.consul.discovery.service-name:${spring.application.name:}}")
|
|
|
|
|
private String serviceName;
|
|
|
|
|
|
|
|
|
|
@Value("${spring.cloud.consul.discovery.ip-address:}")
|
|
|
|
|
private String ipAddress;
|
|
|
|
|
|
|
|
|
|
@Value("${spring.cloud.consul.discovery.prefer-ip-address:#{'false'}}")
|
|
|
|
|
private boolean preferIpAddress;
|
|
|
|
|
|
|
|
|
|
public String getHost() {
|
|
|
|
@ -109,50 +101,10 @@ public class ConsulContextProperties {
|
|
|
|
|
return register;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setRegister(boolean register) {
|
|
|
|
|
this.register = register;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isDiscoveryEnabled() {
|
|
|
|
|
return discoveryEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDiscoveryEnabled(boolean discoveryEnabled) {
|
|
|
|
|
this.discoveryEnabled = discoveryEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getInstanceId() {
|
|
|
|
|
return instanceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setInstanceId(String instanceId) {
|
|
|
|
|
this.instanceId = instanceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getServiceName() {
|
|
|
|
|
return serviceName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setServiceName(String serviceName) {
|
|
|
|
|
this.serviceName = serviceName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getIpAddress() {
|
|
|
|
|
return ipAddress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setIpAddress(String ipAddress) {
|
|
|
|
|
this.ipAddress = ipAddress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isPreferIpAddress() {
|
|
|
|
|
return preferIpAddress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPreferIpAddress(boolean preferIpAddress) {
|
|
|
|
|
this.preferIpAddress = preferIpAddress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
|
public ConsulConfigModifier consulConfigModifier() {
|
|
|
|
|