繁体   English   中英

Spring Cloud Kubernetes FeignClient错误

[英]Spring Cloud Kubernetes FeignClient Error

我正在将Spring Cloud Kubernetes与Spring Boot配合使用,并满足项目所需的RBAC要求。

<!-- kubernetes -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-kubernetes</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-kubernetes-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId>
        </dependency>

我在kubernetes中运行2个微服务

  1. my-service
  2. some-service

my-service使用Spring Boot 2.x运行,而some-service使用Spring Boot 1.x运行。 这两个服务都通过Kubernetes Service以及适当的端点公开。

my-serviceapplication.yaml摘录如下。

some-service:
      url: http://some-service:8080
      serviceName: some-service

FeignClient使用如下。

//FeignClient(url = "${some-service.url}") // does not work either
@FeignClient(value = "${some-service.serviceName}")
@RequestMapping("/api")
public interface SomeServiceClient {

我也做了spring.cloud.kubernetes.discovery.enabled=false

有了这个,我希望my-service应该能够通过kubernetes服务发现与some-service进行对话,但是我遇到了这个错误。

ERROR c.b.d.m.s.c.MatchCoordinator - error=FeignException: status 404 reading SomeServiceClient#get(Test
ion,Output) stacktrace=feign.FeignException: status 404 reading SomeServiceClient#get

我无法理解我在做什么错。 我也没有为some-service设置spring.application.name,因为它是第三方服务。

有人可以帮忙吗? 另外请您了解,这些服务可以通过端口转发正常运行,并且可以通过Ingress进行访问。

如果您没有为某项服务设置名称,而它是第三方服务,那么我认为更好的方法是通过RestTemplate或其他名称来调用它。

伪客户端需要配置并知道服务名称,以便它使用服务发现来调用网络中的特定服务。

好吧,我发现差异在于某项some-service ,其中的有效负载已更新,而my-service FeignClient未更新。 因此导致HTTP 404错误。 但是,它现在可以正确地与FeignClient使用,并且能够正确地使用服务名称进行服务发现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM