這個報錯以後你去查看左右的機器端口占用情況,你就會發現8761端口任何服務都沒有佔用。所以的最大原因可能是沒有覆蓋SpringCloud中默認的配置。下面是SpringCloud的源碼
// // 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; @NestedConfigurationProperty private 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; }
問題就是出到了 this.serviceUrl.put("defaultZone", "http://localhost:8761/eureka/");這句代碼上,它給了個默認的。你要是在註冊中心不配置serviceUrl的話就會出現這個問題了,所以必須配置。配置了以後會覆蓋默認的。