【问题标题】:spring-boot eureka client error "Cannot execute request on any known server"spring-boot eureka 客户端错误“无法在任何已知服务器上执行请求”
【发布时间】:2021-04-19 13:02:06
【问题描述】:

我正在尝试使用 spring-boot 的 eureka。我成功启动了 eureka-server。它在 localhost:8761 运行。
现在我尝试了尤里卡客户端。代码是这样的

import ch.qos.logback.classic.Logger;
import java.util.List;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class ServiceConsumerApplication {

    public static void main(String[] args) {
            SpringApplication.run(ServiceConsumerApplication.class, args);
    }
    
}

@RestController
class EurekaTestController {
    private static Logger LOGGER = (Logger)LoggerFactory.getLogger(EurekaTestController.class);
    
    @Autowired
    DiscoveryClient discoveryClient;
    
    
    @GetMapping("/service-instances/{applicationName}")
    public List<ServiceInstance> getServiceInstance(@PathVariable("applicationName") String appName) {
        List<ServiceInstance> serviceInstances = discoveryClient.getInstances(appName);
        LOGGER.info("{}", serviceInstances);
        return discoveryClient.getInstances(appName);
    }
}

pom.xml 如下:

<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.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.shades</groupId>
    <artifactId>service-consumer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2020.0.0</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </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>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>

</project>

为此项目定义的属性

server.port=8080
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8761/eureka}
spring.application.name=eureka-client

现在,当我在浏览器中打开 http://localhost:8761/eureka 并在 eureka-client 应用程序上方启动时,它会显示应用程序处于 UP 状态。但是当我在应用程序的日志中看到这一点时。

Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=Error while extracting response for type [class org.springframework.cloud.netflix.eureka.http.EurekaApplications] and content type [application/json;charset=UTF-8]; 
nested exception is org.springframework.http.converter.HttpMessageNotReadableException: 
JSON parse error: Cannot deserialize instance of `java.util.ArrayList<com.netflix.appinfo.InstanceInfo>` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList<com.netflix.appinfo.InstanceInfo>` out of START_OBJECT token
 at [Source: (PushbackInputStream); line: 1, column: 122] (through reference chain: com.netflix.discovery.converters.jackson.builder.ApplicationsJacksonBuilder["application"]->java.util.ArrayList[0]->com.netflix.discovery.shared.Application["instance"]) 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;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.util.ArrayList<com.netflix.appinfo.InstanceInfo>` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList<com.netflix.appinfo.InstanceInfo>` out of START_OBJECT token
 at [Source: (PushbackInputStream); line: 1, column: 122] (through reference chain: com.netflix.discovery.converters.jackson.builder.ApplicationsJacksonBuilder["application"]->java.util.ArrayList[0]->com.netflix.discovery.shared.Application["instance"])

后来也看到了


2021-01-14 19:13:20.586  WARN 7970 --- [tbeatExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: Error while extracting response for type [class com.netflix.appinfo.InstanceInfo] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Root name 'timestamp' does not match expected ('instance') for type [simple type, class com.netflix.appinfo.InstanceInfo]; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Root name 'timestamp' does not match expected ('instance') for type [simple type, class com.netflix.appinfo.InstanceInfo]
 at [Source: (PushbackInputStream); line: 1, column: 2] (through reference chain: com.netflix.appinfo.InstanceInfo["timestamp"])
2021-01-14 19:13:20.590 ERROR 7970 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_EUREKA-CLIENT/192.168.43.183:eureka-client:8080 - was unable to send heartbeat!

这可能是什么?
请帮忙

【问题讨论】:

    标签: java spring-boot netflix-eureka service-discovery


    【解决方案1】:

    我有一个类似的问题,并设法通过添加解决它

    @EnableEurekaClient
    

    在我的客户端中的 SpintBootApplication 上方。

    【讨论】:

      猜你喜欢
      • 2018-12-24
      • 2020-04-03
      • 2018-02-18
      • 1970-01-01
      • 2018-01-11
      • 2019-05-10
      • 2018-11-05
      • 1970-01-01
      • 2015-04-11
      相关资源
      最近更新 更多