本文为joshua317原创文章,转载请注明:转载自joshua317博客 Spring Boot-yaml格式,eureka客户端配置default-zone报错问题 - joshua317的博客

一、问题

在配置eureka客户端的时候,设定好eureka客户端的简单配置,配置如下:

server:port: 8081error:path: ./logs/error
eureka:client:service-url:default-zone: http://eureka.joshua317.com/eureka/

结果运行后,报了以下错误:

  .   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::                (v2.5.5)2021-09-29 15:55:00.825  INFO 12672 --- [           main] com.joshua317.demo.DemoApplication       : Starting DemoApplication using Java 1.8.0_281 on joshua with PID 12672 (E:\java\demo\target\classes started by joshua317 in E:\java\demo)
2021-09-29 15:55:00.827  INFO 12672 --- [           main] com.joshua317.demo.DemoApplication       : The following profiles are active: dev
2021-09-29 15:55:01.465  INFO 12672 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=77e68b99-4210-3ba6-ae6f-308380a46828
2021-09-29 15:55:01.696  INFO 12672 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
2021-09-29 15:55:01.705  INFO 12672 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-09-29 15:55:01.706  INFO 12672 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.53]
2021-09-29 15:55:01.829  INFO 12672 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-09-29 15:55:01.829  INFO 12672 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 966 ms
2021-09-29 15:55:05.597  INFO 12672 --- [           main] DiscoveryClientOptionalArgsConfiguration : Eureka HTTP Client uses RestTemplate.
2021-09-29 15:55:08.935  WARN 12672 --- [           main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2021-09-29 15:55:08.991  INFO 12672 --- [           main] o.s.c.n.eureka.InstanceInfoFactory       : Setting initial instance status as: STARTING
2021-09-29 15:55:09.020  INFO 12672 --- [           main] com.netflix.discovery.DiscoveryClient    : Initializing Eureka in region us-east-1
2021-09-29 15:55:09.024  INFO 12672 --- [           main] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration
2021-09-29 15:55:09.049  INFO 12672 --- [           main] com.netflix.discovery.DiscoveryClient    : Disable delta property : false
2021-09-29 15:55:09.049  INFO 12672 --- [           main] com.netflix.discovery.DiscoveryClient    : Single vip registry refresh property : null
2021-09-29 15:55:09.050  INFO 12672 --- [           main] com.netflix.discovery.DiscoveryClient    : Force full registry fetch : false
2021-09-29 15:55:09.050  INFO 12672 --- [           main] com.netflix.discovery.DiscoveryClient    : Application is null : false
2021-09-29 15:55:09.050  INFO 12672 --- [           main] com.netflix.discovery.DiscoveryClient    : Registered Applications size is zero : true
2021-09-29 15:55:09.050  INFO 12672 --- [           main] com.netflix.discovery.DiscoveryClient    : Application version is -1: true
2021-09-29 15:55:09.050  INFO 12672 --- [           main] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
2021-09-29 15:55:15.705  INFO 12672 --- [           main] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connectat org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785)at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)at org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.getApplicationsInternal(RestTemplateEurekaHttpClient.java:145)at org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.getApplications(RestTemplateEurekaHttpClient.java:135)at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:121)at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:80)at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:120)at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1101)at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:1014)at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:441)at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:283)at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:279)at org.springframework.cloud.netflix.eureka.CloudEurekaClient.<init>(CloudEurekaClient.java:66)at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.eurekaClient(EurekaClientAutoConfiguration.java:295)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:374)at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:376)at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:179)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:371)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getTargetObject(EurekaRegistration.java:127)at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient(EurekaRegistration.java:115)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282)at org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:485)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration$$EnhancerBySpringCGLIB$$dd5063c0.getEurekaClient(<generated>)at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:54)at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:38)at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:83)at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)at java.lang.Iterable.forEach(Iterable.java:75)at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)at com.joshua317.demo.DemoApplication.main(DemoApplication.java:10)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connectat org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376)at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:776)... 68 more
Caused by: java.net.ConnectException: Connection refused: connectat java.net.DualStackPlainSocketImpl.connect0(Native Method)at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200)at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:162)at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394)at java.net.Socket.connect(Socket.java:606)at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)... 81 more

看了下报错信息,主要原因是没有获取到配置里面的eureka服务eureka.service-url,而是走了eureka默认的服务地址http://localhost:8761/eureka/,然后默认的的确没有这个服务,就导致报错

2021-09-29 15:55:15.705  INFO 12672 --- [           main] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connectCaused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect

但是为什么没有获取到配置里面的地址,而走了默认的服务地址呢?接下来我们来看看是何原因呢?

二、版本说明

首先说明下此次出现问题的软件版本说明

Spring Boot: v2.5.5

Spring Cloud: 2020.0.4

jdk:1.8

pom.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.5</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.joshua317</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><name>demo</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><spring-cloud.version>2020.0.4</spring-cloud.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>

三、解决

为了避免问题分析过程繁琐,先说解决方案,把问题解决后再去看原理

方案一:

把配置里面的default-zone换成defaultZone

server:port: 8081error:path: ./logs/error
eureka:client:service-url:defaultZone: http://eureka.joshua317.com/eureka/

方案二:

指定eureka.client.regioneureka.client.availability-zones等属性值

server:port: 8081error:path: ./logs/error
eureka:client:region: defaultavailability-zones:default: default-zoneservice-url:default-zone: http://eureka.joshua317.com/eureka/

其中,eureka.client.region属性可理解为是地理上的分区,比如北京,上海这种,或者可以自定义,一个服务只能属于一个Region;

eureka.client.availability-zones属性就是可用的Zone的集合,Zone表示一个区域,常用于实现不同网络分区的实例配置,已实现负载均衡的区域亲和性。一个Region可以包含多个Zone

eureka.client.service-url属性就是服务的url,eureka的服务地址

比如我们可以如下配置,设置多个zone,每个zone对应一个eureka服务地址

server:port: 8081error:path: ./logs/error
eureka:client:region: beijingavailability-zones:beijing: beijing-zone1,beijing-zone2,beijing-zone3service-url:beijing-zone1: http://eureka-server1:8761/eureka/beijing-zone2: http://eureka-server2:8762/eureka/beijing-zone2: http://eureka-server3:8763/eureka/

具体使用哪个方案,可根据我们项目的实际情况进行选择

拓展:

eureka.instance.lease-renewal-interval-in-seconds控制心跳周期间隔时间,如:eureka.instance.lease-renewal-interval-in-seconds=30

eureka.instance.lease-expiration-duration-in-seconds控制服务时效的时间,指定距离最后一次心跳时间多少秒后未续约,则让注册中心剔除实例(需要同时关闭保护模式才能使过期节点被剔除),如:

eureka.instance.lease-expiration-duration-in-seconds=120

四、问题分析

我们第一部分问题的时候提到配置没有获取到,没有生效,既然问题源于配置文件没有生效,那么Spring Boot是如何加载配置的呢eureka.clinet的配置文件呢?现在我们来分析下eureka客户端获取配置的原理。

我们通过ctrl+shift+N搜索下eureka相关的文件,找到EurekaClientConfig,可以看到是一个interface接口文件,看下这个文件的内容

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//package com.netflix.discovery;import com.google.inject.ImplementedBy;
import com.netflix.discovery.shared.transport.EurekaTransportConfig;
import java.util.List;
import javax.annotation.Nullable;@ImplementedBy(DefaultEurekaClientConfig.class)
public interface EurekaClientConfig {int getRegistryFetchIntervalSeconds();int getInstanceInfoReplicationIntervalSeconds();int getInitialInstanceInfoReplicationIntervalSeconds();int getEurekaServiceUrlPollIntervalSeconds();String getProxyHost();String getProxyPort();String getProxyUserName();String getProxyPassword();/** @deprecated */boolean shouldGZipContent();int getEurekaServerReadTimeoutSeconds();int getEurekaServerConnectTimeoutSeconds();String getBackupRegistryImpl();int getEurekaServerTotalConnections();int getEurekaServerTotalConnectionsPerHost();String getEurekaServerURLContext();String getEurekaServerPort();String getEurekaServerDNSName();boolean shouldUseDnsForFetchingServiceUrls();boolean shouldRegisterWithEureka();default boolean shouldUnregisterOnShutdown() {return true;}boolean shouldPreferSameZoneEureka();boolean allowRedirects();boolean shouldLogDeltaDiff();boolean shouldDisableDelta();@NullableString fetchRegistryForRemoteRegions();String getRegion();String[] getAvailabilityZones(String var1);List<String> getEurekaServerServiceUrls(String var1);boolean shouldFilterOnlyUpInstances();int getEurekaConnectionIdleTimeoutSeconds();boolean shouldFetchRegistry();default boolean shouldEnforceFetchRegistryAtInit() {return false;}@NullableString getRegistryRefreshSingleVipAddress();int getHeartbeatExecutorThreadPoolSize();int getHeartbeatExecutorExponentialBackOffBound();int getCacheRefreshExecutorThreadPoolSize();int getCacheRefreshExecutorExponentialBackOffBound();String getDollarReplacement();String getEscapeCharReplacement();boolean shouldOnDemandUpdateStatusChange();default boolean shouldEnforceRegistrationAtInit() {return false;}String getEncoderName();String getDecoderName();String getClientDataAccept();String getExperimental(String var1);EurekaTransportConfig getTransportConfig();
}

通过查看,发现有一个List对象的方法:getEurekaServerServiceUrls

我们看下是哪个类实现了这个接口,经查找EurekaClientConfigBean类实现了该接口的方法

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//package org.springframework.cloud.netflix.eureka;import com.netflix.appinfo.EurekaAccept;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.EurekaTransportConfig;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.Ordered;
import org.springframework.core.env.PropertyResolver;
import org.springframework.util.StringUtils;@ConfigurationProperties("eureka.client")
public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {public static final String PREFIX = "eureka.client";public static final String DEFAULT_URL = "http://localhost:8761/eureka/";public static final String DEFAULT_ZONE = "defaultZone";private static final int MINUTES = 60;@Autowired(required = false)PropertyResolver propertyResolver;private boolean enabled = true;@NestedConfigurationPropertyprivate EurekaTransportConfig transport = new CloudEurekaTransportConfig();private int registryFetchIntervalSeconds = 30;private int instanceInfoReplicationIntervalSeconds = 30;private int initialInstanceInfoReplicationIntervalSeconds = 40;private int eurekaServiceUrlPollIntervalSeconds = 300;private String proxyPort;private String proxyHost;private String proxyUserName;private String proxyPassword;private int eurekaServerReadTimeoutSeconds = 8;private int eurekaServerConnectTimeoutSeconds = 5;private String backupRegistryImpl;private int eurekaServerTotalConnections = 200;private int eurekaServerTotalConnectionsPerHost = 50;private String eurekaServerURLContext;private String eurekaServerPort;private String eurekaServerDNSName;private String region = "us-east-1";private int eurekaConnectionIdleTimeoutSeconds = 30;private String registryRefreshSingleVipAddress;private int heartbeatExecutorThreadPoolSize = 2;private int heartbeatExecutorExponentialBackOffBound = 10;private int cacheRefreshExecutorThreadPoolSize = 2;private int cacheRefreshExecutorExponentialBackOffBound = 10;private Map<String, String> serviceUrl = new HashMap();private boolean gZipContent;private boolean useDnsForFetchingServiceUrls;private boolean registerWithEureka;private boolean preferSameZoneEureka;private boolean logDeltaDiff;private boolean disableDelta;private String fetchRemoteRegionsRegistry;private Map<String, String> availabilityZones;private boolean filterOnlyUpInstances;private boolean fetchRegistry;private String dollarReplacement;private String escapeCharReplacement;private boolean allowRedirects;private boolean onDemandUpdateStatusChange;private String encoderName;private String decoderName;private String clientDataAccept;private boolean shouldUnregisterOnShutdown;private boolean shouldEnforceRegistrationAtInit;private int order;public EurekaClientConfigBean() {this.serviceUrl.put("defaultZone", "http://localhost:8761/eureka/");this.gZipContent = true;this.useDnsForFetchingServiceUrls = false;this.registerWithEureka = true;this.preferSameZoneEureka = true;this.availabilityZones = new HashMap();this.filterOnlyUpInstances = true;this.fetchRegistry = true;this.dollarReplacement = "_-";this.escapeCharReplacement = "__";this.allowRedirects = false;this.onDemandUpdateStatusChange = true;this.clientDataAccept = EurekaAccept.full.name();this.shouldUnregisterOnShutdown = true;this.shouldEnforceRegistrationAtInit = false;this.order = 0;}public boolean shouldGZipContent() {return this.gZipContent;}public boolean shouldUseDnsForFetchingServiceUrls() {return this.useDnsForFetchingServiceUrls;}public boolean shouldRegisterWithEureka() {return this.registerWithEureka;}public boolean shouldPreferSameZoneEureka() {return this.preferSameZoneEureka;}public boolean shouldLogDeltaDiff() {return this.logDeltaDiff;}public boolean shouldDisableDelta() {return this.disableDelta;}public boolean shouldUnregisterOnShutdown() {return this.shouldUnregisterOnShutdown;}public boolean shouldEnforceRegistrationAtInit() {return this.shouldEnforceRegistrationAtInit;}public String fetchRegistryForRemoteRegions() {return this.fetchRemoteRegionsRegistry;}public String[] getAvailabilityZones(String region) {String value = (String)this.availabilityZones.get(region);if (value == null) {value = "defaultZone";}return value.split(",");}public List<String> getEurekaServerServiceUrls(String myZone) {String serviceUrls = (String)this.serviceUrl.get(myZone);if (serviceUrls == null || serviceUrls.isEmpty()) {serviceUrls = (String)this.serviceUrl.get("defaultZone");}if (!StringUtils.isEmpty(serviceUrls)) {String[] serviceUrlsSplit = StringUtils.commaDelimitedListToStringArray(serviceUrls);List<String> eurekaServiceUrls = new ArrayList(serviceUrlsSplit.length);String[] var5 = serviceUrlsSplit;int var6 = serviceUrlsSplit.length;for(int var7 = 0; var7 < var6; ++var7) {String eurekaServiceUrl = var5[var7];if (!this.endsWithSlash(eurekaServiceUrl)) {eurekaServiceUrl = eurekaServiceUrl + "/";}eurekaServiceUrls.add(eurekaServiceUrl.trim());}return eurekaServiceUrls;} else {return new ArrayList();}}private boolean endsWithSlash(String url) {return url.endsWith("/");}public boolean shouldFilterOnlyUpInstances() {return this.filterOnlyUpInstances;}public boolean shouldFetchRegistry() {return this.fetchRegistry;}public boolean allowRedirects() {return this.allowRedirects;}public boolean shouldOnDemandUpdateStatusChange() {return this.onDemandUpdateStatusChange;}public String getExperimental(String name) {return this.propertyResolver != null ? (String)this.propertyResolver.getProperty("eureka.client.experimental." + name, String.class, (Object)null) : null;}public EurekaTransportConfig getTransportConfig() {return this.getTransport();}public PropertyResolver getPropertyResolver() {return this.propertyResolver;}public void setPropertyResolver(PropertyResolver propertyResolver) {this.propertyResolver = propertyResolver;}public boolean isEnabled() {return this.enabled;}public void setEnabled(boolean enabled) {this.enabled = enabled;}public EurekaTransportConfig getTransport() {return this.transport;}public void setTransport(EurekaTransportConfig transport) {this.transport = transport;}public int getRegistryFetchIntervalSeconds() {return this.registryFetchIntervalSeconds;}public void setRegistryFetchIntervalSeconds(int registryFetchIntervalSeconds) {this.registryFetchIntervalSeconds = registryFetchIntervalSeconds;}public int getInstanceInfoReplicationIntervalSeconds() {return this.instanceInfoReplicationIntervalSeconds;}public void setInstanceInfoReplicationIntervalSeconds(int instanceInfoReplicationIntervalSeconds) {this.instanceInfoReplicationIntervalSeconds = instanceInfoReplicationIntervalSeconds;}public int getInitialInstanceInfoReplicationIntervalSeconds() {return this.initialInstanceInfoReplicationIntervalSeconds;}public void setInitialInstanceInfoReplicationIntervalSeconds(int initialInstanceInfoReplicationIntervalSeconds) {this.initialInstanceInfoReplicationIntervalSeconds = initialInstanceInfoReplicationIntervalSeconds;}public int getEurekaServiceUrlPollIntervalSeconds() {return this.eurekaServiceUrlPollIntervalSeconds;}public void setEurekaServiceUrlPollIntervalSeconds(int eurekaServiceUrlPollIntervalSeconds) {this.eurekaServiceUrlPollIntervalSeconds = eurekaServiceUrlPollIntervalSeconds;}public String getProxyPort() {return this.proxyPort;}public void setProxyPort(String proxyPort) {this.proxyPort = proxyPort;}public String getProxyHost() {return this.proxyHost;}public void setProxyHost(String proxyHost) {this.proxyHost = proxyHost;}public String getProxyUserName() {return this.proxyUserName;}public void setProxyUserName(String proxyUserName) {this.proxyUserName = proxyUserName;}public String getProxyPassword() {return this.proxyPassword;}public void setProxyPassword(String proxyPassword) {this.proxyPassword = proxyPassword;}public int getEurekaServerReadTimeoutSeconds() {return this.eurekaServerReadTimeoutSeconds;}public void setEurekaServerReadTimeoutSeconds(int eurekaServerReadTimeoutSeconds) {this.eurekaServerReadTimeoutSeconds = eurekaServerReadTimeoutSeconds;}public int getEurekaServerConnectTimeoutSeconds() {return this.eurekaServerConnectTimeoutSeconds;}public void setEurekaServerConnectTimeoutSeconds(int eurekaServerConnectTimeoutSeconds) {this.eurekaServerConnectTimeoutSeconds = eurekaServerConnectTimeoutSeconds;}public String getBackupRegistryImpl() {return this.backupRegistryImpl;}public void setBackupRegistryImpl(String backupRegistryImpl) {this.backupRegistryImpl = backupRegistryImpl;}public int getEurekaServerTotalConnections() {return this.eurekaServerTotalConnections;}public void setEurekaServerTotalConnections(int eurekaServerTotalConnections) {this.eurekaServerTotalConnections = eurekaServerTotalConnections;}public int getEurekaServerTotalConnectionsPerHost() {return this.eurekaServerTotalConnectionsPerHost;}public void setEurekaServerTotalConnectionsPerHost(int eurekaServerTotalConnectionsPerHost) {this.eurekaServerTotalConnectionsPerHost = eurekaServerTotalConnectionsPerHost;}public String getEurekaServerURLContext() {return this.eurekaServerURLContext;}public void setEurekaServerURLContext(String eurekaServerURLContext) {this.eurekaServerURLContext = eurekaServerURLContext;}public String getEurekaServerPort() {return this.eurekaServerPort;}public void setEurekaServerPort(String eurekaServerPort) {this.eurekaServerPort = eurekaServerPort;}public String getEurekaServerDNSName() {return this.eurekaServerDNSName;}public void setEurekaServerDNSName(String eurekaServerDNSName) {this.eurekaServerDNSName = eurekaServerDNSName;}public String getRegion() {return this.region;}public void setRegion(String region) {this.region = region;}public int getEurekaConnectionIdleTimeoutSeconds() {return this.eurekaConnectionIdleTimeoutSeconds;}public void setEurekaConnectionIdleTimeoutSeconds(int eurekaConnectionIdleTimeoutSeconds) {this.eurekaConnectionIdleTimeoutSeconds = eurekaConnectionIdleTimeoutSeconds;}public String getRegistryRefreshSingleVipAddress() {return this.registryRefreshSingleVipAddress;}public void setRegistryRefreshSingleVipAddress(String registryRefreshSingleVipAddress) {this.registryRefreshSingleVipAddress = registryRefreshSingleVipAddress;}public int getHeartbeatExecutorThreadPoolSize() {return this.heartbeatExecutorThreadPoolSize;}public void setHeartbeatExecutorThreadPoolSize(int heartbeatExecutorThreadPoolSize) {this.heartbeatExecutorThreadPoolSize = heartbeatExecutorThreadPoolSize;}public int getHeartbeatExecutorExponentialBackOffBound() {return this.heartbeatExecutorExponentialBackOffBound;}public void setHeartbeatExecutorExponentialBackOffBound(int heartbeatExecutorExponentialBackOffBound) {this.heartbeatExecutorExponentialBackOffBound = heartbeatExecutorExponentialBackOffBound;}public int getCacheRefreshExecutorThreadPoolSize() {return this.cacheRefreshExecutorThreadPoolSize;}public void setCacheRefreshExecutorThreadPoolSize(int cacheRefreshExecutorThreadPoolSize) {this.cacheRefreshExecutorThreadPoolSize = cacheRefreshExecutorThreadPoolSize;}public int getCacheRefreshExecutorExponentialBackOffBound() {return this.cacheRefreshExecutorExponentialBackOffBound;}public void setCacheRefreshExecutorExponentialBackOffBound(int cacheRefreshExecutorExponentialBackOffBound) {this.cacheRefreshExecutorExponentialBackOffBound = cacheRefreshExecutorExponentialBackOffBound;}public Map<String, String> getServiceUrl() {return this.serviceUrl;}public void setServiceUrl(Map<String, String> serviceUrl) {this.serviceUrl = serviceUrl;}public boolean isgZipContent() {return this.gZipContent;}public void setgZipContent(boolean gZipContent) {this.gZipContent = gZipContent;}public boolean isUseDnsForFetchingServiceUrls() {return this.useDnsForFetchingServiceUrls;}public void setUseDnsForFetchingServiceUrls(boolean useDnsForFetchingServiceUrls) {this.useDnsForFetchingServiceUrls = useDnsForFetchingServiceUrls;}public boolean isRegisterWithEureka() {return this.registerWithEureka;}public void setRegisterWithEureka(boolean registerWithEureka) {this.registerWithEureka = registerWithEureka;}public boolean isPreferSameZoneEureka() {return this.preferSameZoneEureka;}public void setPreferSameZoneEureka(boolean preferSameZoneEureka) {this.preferSameZoneEureka = preferSameZoneEureka;}public boolean isLogDeltaDiff() {return this.logDeltaDiff;}public void setLogDeltaDiff(boolean logDeltaDiff) {this.logDeltaDiff = logDeltaDiff;}public boolean isDisableDelta() {return this.disableDelta;}public void setDisableDelta(boolean disableDelta) {this.disableDelta = disableDelta;}public String getFetchRemoteRegionsRegistry() {return this.fetchRemoteRegionsRegistry;}public void setFetchRemoteRegionsRegistry(String fetchRemoteRegionsRegistry) {this.fetchRemoteRegionsRegistry = fetchRemoteRegionsRegistry;}public Map<String, String> getAvailabilityZones() {return this.availabilityZones;}public void setAvailabilityZones(Map<String, String> availabilityZones) {this.availabilityZones = availabilityZones;}public boolean isFilterOnlyUpInstances() {return this.filterOnlyUpInstances;}public void setFilterOnlyUpInstances(boolean filterOnlyUpInstances) {this.filterOnlyUpInstances = filterOnlyUpInstances;}public boolean isFetchRegistry() {return this.fetchRegistry;}public void setFetchRegistry(boolean fetchRegistry) {this.fetchRegistry = fetchRegistry;}public String getDollarReplacement() {return this.dollarReplacement;}public void setDollarReplacement(String dollarReplacement) {this.dollarReplacement = dollarReplacement;}public String getEscapeCharReplacement() {return this.escapeCharReplacement;}public void setEscapeCharReplacement(String escapeCharReplacement) {this.escapeCharReplacement = escapeCharReplacement;}public boolean isAllowRedirects() {return this.allowRedirects;}public void setAllowRedirects(boolean allowRedirects) {this.allowRedirects = allowRedirects;}public boolean isOnDemandUpdateStatusChange() {return this.onDemandUpdateStatusChange;}public void setOnDemandUpdateStatusChange(boolean onDemandUpdateStatusChange) {this.onDemandUpdateStatusChange = onDemandUpdateStatusChange;}public String getEncoderName() {return this.encoderName;}public void setEncoderName(String encoderName) {this.encoderName = encoderName;}public String getDecoderName() {return this.decoderName;}public void setDecoderName(String decoderName) {this.decoderName = decoderName;}public String getClientDataAccept() {return this.clientDataAccept;}public void setClientDataAccept(String clientDataAccept) {this.clientDataAccept = clientDataAccept;}public boolean isShouldUnregisterOnShutdown() {return this.shouldUnregisterOnShutdown;}public void setShouldUnregisterOnShutdown(boolean shouldUnregisterOnShutdown) {this.shouldUnregisterOnShutdown = shouldUnregisterOnShutdown;}public boolean isShouldEnforceRegistrationAtInit() {return this.shouldEnforceRegistrationAtInit;}public void setShouldEnforceRegistrationAtInit(boolean shouldEnforceRegistrationAtInit) {this.shouldEnforceRegistrationAtInit = shouldEnforceRegistrationAtInit;}public int getOrder() {return this.order;}public void setOrder(int order) {this.order = order;}public boolean equals(Object o) {if (this == o) {return true;} else if (o != null && this.getClass() == o.getClass()) {EurekaClientConfigBean that = (EurekaClientConfigBean)o;return Objects.equals(this.propertyResolver, that.propertyResolver) && this.enabled == that.enabled && Objects.equals(this.transport, that.transport) && this.registryFetchIntervalSeconds == that.registryFetchIntervalSeconds && this.instanceInfoReplicationIntervalSeconds == that.instanceInfoReplicationIntervalSeconds && this.initialInstanceInfoReplicationIntervalSeconds == that.initialInstanceInfoReplicationIntervalSeconds && this.eurekaServiceUrlPollIntervalSeconds == that.eurekaServiceUrlPollIntervalSeconds && this.eurekaServerReadTimeoutSeconds == that.eurekaServerReadTimeoutSeconds && this.eurekaServerConnectTimeoutSeconds == that.eurekaServerConnectTimeoutSeconds && this.eurekaServerTotalConnections == that.eurekaServerTotalConnections && this.eurekaServerTotalConnectionsPerHost == that.eurekaServerTotalConnectionsPerHost && this.eurekaConnectionIdleTimeoutSeconds == that.eurekaConnectionIdleTimeoutSeconds && this.heartbeatExecutorThreadPoolSize == that.heartbeatExecutorThreadPoolSize && this.heartbeatExecutorExponentialBackOffBound == that.heartbeatExecutorExponentialBackOffBound && this.cacheRefreshExecutorThreadPoolSize == that.cacheRefreshExecutorThreadPoolSize && this.cacheRefreshExecutorExponentialBackOffBound == that.cacheRefreshExecutorExponentialBackOffBound && this.gZipContent == that.gZipContent && this.useDnsForFetchingServiceUrls == that.useDnsForFetchingServiceUrls && this.registerWithEureka == that.registerWithEureka && this.preferSameZoneEureka == that.preferSameZoneEureka && this.logDeltaDiff == that.logDeltaDiff && this.disableDelta == that.disableDelta && this.filterOnlyUpInstances == that.filterOnlyUpInstances && this.fetchRegistry == that.fetchRegistry && this.allowRedirects == that.allowRedirects && this.onDemandUpdateStatusChange == that.onDemandUpdateStatusChange && this.shouldUnregisterOnShutdown == that.shouldUnregisterOnShutdown && this.shouldEnforceRegistrationAtInit == that.shouldEnforceRegistrationAtInit && Objects.equals(this.proxyPort, that.proxyPort) && Objects.equals(this.proxyHost, that.proxyHost) && Objects.equals(this.proxyUserName, that.proxyUserName) && Objects.equals(this.proxyPassword, that.proxyPassword) && Objects.equals(this.backupRegistryImpl, that.backupRegistryImpl) && Objects.equals(this.eurekaServerURLContext, that.eurekaServerURLContext) && Objects.equals(this.eurekaServerPort, that.eurekaServerPort) && Objects.equals(this.eurekaServerDNSName, that.eurekaServerDNSName) && Objects.equals(this.region, that.region) && Objects.equals(this.registryRefreshSingleVipAddress, that.registryRefreshSingleVipAddress) && Objects.equals(this.serviceUrl, that.serviceUrl) && Objects.equals(this.fetchRemoteRegionsRegistry, that.fetchRemoteRegionsRegistry) && Objects.equals(this.availabilityZones, that.availabilityZones) && Objects.equals(this.dollarReplacement, that.dollarReplacement) && Objects.equals(this.escapeCharReplacement, that.escapeCharReplacement) && Objects.equals(this.encoderName, that.encoderName) && Objects.equals(this.decoderName, that.decoderName) && Objects.equals(this.clientDataAccept, that.clientDataAccept) && Objects.equals(this.order, that.order);} else {return false;}}public int hashCode() {return Objects.hash(new Object[]{this.propertyResolver, this.enabled, this.transport, this.registryFetchIntervalSeconds, this.instanceInfoReplicationIntervalSeconds, this.initialInstanceInfoReplicationIntervalSeconds, this.eurekaServiceUrlPollIntervalSeconds, this.proxyPort, this.proxyHost, this.proxyUserName, this.proxyPassword, this.eurekaServerReadTimeoutSeconds, this.eurekaServerConnectTimeoutSeconds, this.backupRegistryImpl, this.eurekaServerTotalConnections, this.eurekaServerTotalConnectionsPerHost, this.eurekaServerURLContext, this.eurekaServerPort, this.eurekaServerDNSName, this.region, this.eurekaConnectionIdleTimeoutSeconds, this.registryRefreshSingleVipAddress, this.heartbeatExecutorThreadPoolSize, this.heartbeatExecutorExponentialBackOffBound, this.cacheRefreshExecutorThreadPoolSize, this.cacheRefreshExecutorExponentialBackOffBound, this.serviceUrl, this.gZipContent, this.useDnsForFetchingServiceUrls, this.registerWithEureka, this.preferSameZoneEureka, this.logDeltaDiff, this.disableDelta, this.fetchRemoteRegionsRegistry, this.availabilityZones, this.filterOnlyUpInstances, this.fetchRegistry, this.dollarReplacement, this.escapeCharReplacement, this.allowRedirects, this.onDemandUpdateStatusChange, this.encoderName, this.decoderName, this.clientDataAccept, this.shouldUnregisterOnShutdown, this.shouldEnforceRegistrationAtInit, this.order});}public String toString() {return "EurekaClientConfigBean{" + "propertyResolver=" + this.propertyResolver + ", " + "enabled=" + this.enabled + ", " + "transport=" + this.transport + ", " + "registryFetchIntervalSeconds=" + this.registryFetchIntervalSeconds + ", " + "instanceInfoReplicationIntervalSeconds=" + this.instanceInfoReplicationIntervalSeconds + ", " + "initialInstanceInfoReplicationIntervalSeconds=" + this.initialInstanceInfoReplicationIntervalSeconds + ", " + "eurekaServiceUrlPollIntervalSeconds=" + this.eurekaServiceUrlPollIntervalSeconds + ", " + "proxyPort='" + this.proxyPort + "', " + "proxyHost='" + this.proxyHost + "', " + "proxyUserName='" + this.proxyUserName + "', " + "proxyPassword='" + this.proxyPassword + "', " + "eurekaServerReadTimeoutSeconds=" + this.eurekaServerReadTimeoutSeconds + ", " + "eurekaServerConnectTimeoutSeconds=" + this.eurekaServerConnectTimeoutSeconds + ", " + "backupRegistryImpl='" + this.backupRegistryImpl + "', " + "eurekaServerTotalConnections=" + this.eurekaServerTotalConnections + ", " + "eurekaServerTotalConnectionsPerHost=" + this.eurekaServerTotalConnectionsPerHost + ", " + "eurekaServerURLContext='" + this.eurekaServerURLContext + "', " + "eurekaServerPort='" + this.eurekaServerPort + "', " + "eurekaServerDNSName='" + this.eurekaServerDNSName + "', " + "region='" + this.region + "', " + "eurekaConnectionIdleTimeoutSeconds=" + this.eurekaConnectionIdleTimeoutSeconds + ", " + "registryRefreshSingleVipAddress='" + this.registryRefreshSingleVipAddress + "', " + "heartbeatExecutorThreadPoolSize=" + this.heartbeatExecutorThreadPoolSize + ", " + "heartbeatExecutorExponentialBackOffBound=" + this.heartbeatExecutorExponentialBackOffBound + ", " + "cacheRefreshExecutorThreadPoolSize=" + this.cacheRefreshExecutorThreadPoolSize + ", " + "cacheRefreshExecutorExponentialBackOffBound=" + this.cacheRefreshExecutorExponentialBackOffBound + ", " + "serviceUrl=" + this.serviceUrl + ", " + "gZipContent=" + this.gZipContent + ", " + "useDnsForFetchingServiceUrls=" + this.useDnsForFetchingServiceUrls + ", " + "registerWithEureka=" + this.registerWithEureka + ", " + "preferSameZoneEureka=" + this.preferSameZoneEureka + ", " + "logDeltaDiff=" + this.logDeltaDiff + ", " + "disableDelta=" + this.disableDelta + ", " + "fetchRemoteRegionsRegistry='" + this.fetchRemoteRegionsRegistry + "', " + "availabilityZones=" + this.availabilityZones + ", " + "filterOnlyUpInstances=" + this.filterOnlyUpInstances + ", " + "fetchRegistry=" + this.fetchRegistry + ", " + "dollarReplacement='" + this.dollarReplacement + "', " + "escapeCharReplacement='" + this.escapeCharReplacement + "', " + "allowRedirects=" + this.allowRedirects + ", " + "onDemandUpdateStatusChange=" + this.onDemandUpdateStatusChange + ", " + "encoderName='" + this.encoderName + "', " + "decoderName='" + this.decoderName + "', " + "clientDataAccept='" + this.clientDataAccept + "', " + "shouldUnregisterOnShutdown='" + this.shouldUnregisterOnShutdown + "shouldEnforceRegistrationAtInit='" + this.shouldEnforceRegistrationAtInit + "', " + "order='" + this.order + "'}";}
}

接下来,我们断点看一下,发现myZone的值为defaultZone而不是default-zone,有两个serviceUrl,分别是default-zone和defaultZone

default-zone -> http://eureka.joshua317.com/eureka/

defaultZone -> http://localhost:8761/eureka/

在没有制定region的情况下,会使用defaultZone从ServiceUrl中查询Eureka Server的URL列表,所以使用代码默认初始化的地址http://localhost:8761/eureka/,所以出现了上面的错误。

具体为什么呢,我们接着往下走,进入到了EndpointUtils类中的getServiceUrlsMapFromConfig,我们可以看到region为us-east-1默认值

instanceZone="defaultZone"
region="us-east-1"
zone="defaultZone"
availZones[myZoneOffset]="defaultZone"

因为没有在yml配置region属性,所以才使用了默认us-east-1,并且availabilityZones为空。所以myZone使用的是默认是值defaultZone,详情见getZone()方法。

然后我们继续追代码,找到了类ConfigClusterResolvergetClusterEndpointsFromConfig方法,在这里面我们可以看到myZone的获取

那有人可能会问为什么service-url就可以呢,我们在EurekaClientConfigBean类中setServiceUrl方法处断点看下

在EurekaClientConfigBean调用sercviceUrl之前,先经过 BeanProperty.setValue()处理了, 并且beanProperty对象的setter方法正好sercviceUrl,而BeanProperty的属性name是service-url这和我们的配置文件是一样的。

五、总结

在我们配置文件写入配置的过程中,属性里面的一些键名是驼峰,还是中划线,主要看我们底层代码实现是如何处理的,我们可以通过断点追代码进行排查分析。

本文为joshua317原创文章,转载请注明:转载自joshua317博客 Spring Boot-yaml格式,eureka客户端配置default-zone报错问题 - joshua317的博客

Spring Boot-yaml格式,eureka客户端配置default-zone报错问题相关推荐

  1. spring boot ajax 415,解决@RequestBody接收json对象报错415的问题

    @RequestBody接收json对象报错415 前端请求: $.ajax({ url: basePath() + "/index/login.do", type : " ...

  2. oracle tns测试,在客户端配置TNS测试报错ORA-12170:TNS:连接超时

    在Red Hat Enterprise Linux Server Releae 5.5 成功安装ORACLE 10g 后,在客户端配置TNS后,测试是否可以连接到数据块服务器,结果报错: ORA-12 ...

  3. Spring Boot 整合携程Apollo 配置中心

    作者:AaronSimon blog.csdn.net/AaronSimon/article/details/83657612 Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理 ...

  4. 详解Spring Boot配置文件之多环境配置

    一. 多环境配置的好处: 1.不同环境配置可以配置不同的参数~ 2.便于部署,提高效率,减少出错~ 二. properties多环境配置 1. 配置激活选项 spring.profiles.activ ...

  5. JAVA Spring Cloud 注册中心 Eureka 相关配置

    转载至  https://www.cnblogs.com/fangfuhai/p/7070325.html Eureka客户端配置       1.RegistryFetchIntervalSecon ...

  6. [Spring Boot]Druid datasource整合及配置

    [Spring Boot]Druid datasource整合及配置 创建Spring Boot项目 这里使用默认配置创建一个空项目 demo-druid 用作演示,可跳过这一段: 只勾选基本的Spr ...

  7. Spring Boot 面试杀手锏:自动配置原理

    欢迎关注方志朋的博客,回复"666"获面试宝典 不论在工作中,亦或是求职面试,Spring Boot已经成为我们必知必会的技能项.除了某些老旧的政府项目或金融项目持有观望态度外,如 ...

  8. 关于Spring Boot WebSocket整合以及nginx配置详解

    这篇文章主要给大家介绍了关于Spring Boot WebSocket整合以及nginx配置的相关资料,文中通过示例代码给大家介绍的非常详细,相信对大家的学习或者工作具有一定的参考学习价值,需要的朋友 ...

  9. Spring Boot中的一些常用配置介绍!

    这篇教程将为你介绍Spring Boot 中的一些常用配置,比如:自定义 Banner.配置日志.关闭特定的自动配置等. 自定义Banner 在 Spring Boot 启动的时候会有一个默认的启动图 ...

最新文章

  1. 极限脱出 量子计算机,《极限脱出3:零时困境》50条指向zero身份线索
  2. 经典的《JavaScript 权威指南》中的“对象”不经典
  3. 多层mvc,thikphp进阶
  4. python在代码里查看获取模块信息
  5. 网站SEO优化之如何建设外链提升网站权重?
  6. web项目的两个创建形式website和webapplication
  7. 大剑无锋之分布式和微服务分别是什么?【面试推荐】
  8. NET问答: LINQ 中为啥不能将 StartsWith() 转成 Like('abc%') ?
  9. 利用IDLE对 dem进行批量拼接处理
  10. [可道云文件管理kodbox 1.15] 企业网盘+云端文档管理+批量上传下载文件夹+移动端H5优化
  11. C程序设计试题汇编(第三版)谭浩强主编 第二章 选择题解析+总结
  12. python绘制网格地图_「GIS教程」Python-GeoPandas地图、专题地图绘制
  13. win7下vs2017安装奋斗纠结过程
  14. html获取本机ip,获取本机IP地址的实例(JavaScript / Node.js)
  15. 9个动作让网站3天被百度收录!
  16. java 提交mac地址栏_Mac系统快捷键大全 - 米扑博客
  17. 微信如何保存文件?企业微信如何下载文件?
  18. 1449:【例题2】魔板
  19. 重新设置用户名之后vscode连接出错
  20. 峰哥读者高中学历,被忽悠去培训大数据。。

热门文章

  1. 三大期指IF、IC、IH的区别
  2. 任正非:华为是世界上最穷的高科技公司,比任何一个公司都穷
  3. 咖啡卷到现在,他们开始往里面掺北京豆汁了
  4. 使用 AntV S2 打造大数据表格组件
  5. 日本6日游——大阪京都名古屋富士山横滨
  6. C语言数字图像处理进阶---8 Glow Filter
  7. 新超越极限地图和隐藏口令及装备合成公式
  8. 树莓派造服务器(三):内网穿透方案
  9. SharePoint2016配置工作流开发环境
  10. Xcode 史上最全canOpenURL: failed问题解决办法