搭环境时搭建Eureka的集群版,EurekaServer启动都正常,服务注册时报错:
2021-11-25 22:23:35.013 INFO 2248 --- [ restartedMain] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://eureka2.com:7002/eureka02/}, exception=Error while extracting response for type [class org.springframework.cloud.netflix.eureka.http.EurekaApplications] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Root name ('timestamp') does not match expected ('applications') for type `org.springframework.cloud.netflix.eureka.http.EurekaApplications`; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Root name ('timestamp') does not match expected ('applications') for type `org.springframework.cloud.netflix.eureka.http.EurekaApplications`
at [Source: (PushbackInputStream); line: 1, column: 2] (through reference chain: org.springframework.cloud.netflix.eureka.http.EurekaApplications["timestamp"]) stacktrace=org.springframework.web.client.RestClientException: Error while extracting response for type [class org.springframework.cloud.netflix.eureka.http.EurekaApplications] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Root name ('timestamp') does not match expected ('applications') for type `org.springframework.cloud.netflix.eureka.http.EurekaApplications`; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Root name ('timestamp') does not match expected ('applications') for type `org.springframework.cloud.netflix.eureka.http.EurekaApplications`
at [Source: (PushbackInputStream); line: 1, column: 2] (through reference chain: org.springframework.cloud.netflix.eureka.http.EurekaApplications["timestamp"])
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:120)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:1037)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:1020)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:778)
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(Redirecting
最后当我仔细对比我的集群版和单机Eureka服务的配置区别,最终发现原来错在application.yml文件中。
最终解决:Eureka服务的defaultZone地址必须要以/eureka结尾,不能以其他内容结尾(无论Server端还是Client端都是)。
错误 application.yml 示例:
spring:
application:
name: eureka-server
server:
port: 9999
eureka:
server:
enable-self-preservation: false
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:9999/eureka-service/
正确的 application.yml 示例:
spring:
application:
name: eureka-server
server:
port: 9999
eureka:
server:
enable-self-preservation: false
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:9999/eureka/
当然:lcoalhost:9999/a/eureka也是不行的(试过了)