Load balancer does not contain an instance for the service xxx-service

Problem Description:

When using Nacos+SpringBoot+OpenFeign to build a project, Nacos serves as the registration center and configuration center. The application is successfully registered to Nacos, but when the service consumer calls the service through OpenFeign, an error is reported: Load balancer does not contain an instance for the service xxx-service. The solution is as follows:

1. Check the name of the microservice application

  • Check whether the case of application.name is consistent (nacos is more case-sensitive, it is best to use lowercase uniformly)
  • The "_" underscore is changed to a dash "-", and eg: cloud_payment is changed to cloud-payment (otherwise an error may be reported java.lang.IllegalStateException: Service id not legal hostname)
#参考:
spring:
  application:
    name: cloud-payment #微服务应用的名字

2. Check the annotation @FeignClient annotation

Check whether the value configuration of the annotation @FeignClient annotation value is consistent with the service name displayed in nacos (the case must also be consistent)

@FeignClient(value = "cloud-payment",fallback = PaymentFallbackService.class)

Insert image description here

3. Check SpringBoot, SpringCloud, Spring Cloud Alibaba, and Nacos versions

Check whether SpringBoot, SpringCloud, Spring Cloud Alibaba, and Nacos versions are used together. We know that environmental problems are often caused by versions.

Please refer to the SpringBoot, SpringCloud, and Spring Cloud Alibaba version comparison table (detailed and accurate) for processing.

4. Microservices in common namespaces and groups

5. Modify configuration

If the fuse is on, you can check the version:

For versions before springcloud2020, the configuration is as follows:

feign:
  hystrix:
    enable: true

or

feign.hystrix.enabled=true

For springcloud2020 and later versions, the configuration is as follows:

feign:
  circuitbreaker:
    enabled: true

or

feign.circuitbreaker.enabled=true

Restart the service after modifying the configuration.

Okay, that’s it, I hope it solves your problem. If it is not resolved, you can first call the service provider separately to confirm that there is no problem and that it can be successfully injected into the registration center, and then doubt the caller and then the calling process.

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_47061482/article/details/131708340