当前位置:   article > 正文

1-记Eureka新版本客户端无法注册到服务问题_eureka注册不进去

eureka注册不进去

1、Eureka客户端无法注册到服务端问题

版本说明:

  • Spring Boot:3.0.9
  • Spring Cloud:2022.0.4
  • jdk:20

1、配置相关

(1) Eureka服务端

server:
  port: 8091
  # 此处如果配置了context-path,客户端那边的defaultZone就得修改为 http://localhost:8091/eureka/eureka
  # 服务端defaultZone修改为:http://localhost:8091/eureka
  servlet:
	context-path: /eureka
  
eureka:
  client:
    # 不需要获取服务端,将其改为false
    fetch-registry: false
    # 暂时不需要将自己注册到客户端
    register-with-eureka: false
    # 将eureka服务端指向自己
    service-url:
      defaultZone: http://localhost:8091/eureka
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

(2)Eureka客户端

server:
  port: 8082
  servlet:
    context-path: /user
spring:
  application:
    name: userService
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8091
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

2、报错问题:

DiscoveryClient_USERSERVICE/localhost:userService:8082 - was unable to refresh its cache! This periodic background refresh will be retried in 30 seconds. status = Cannot execute request on any known server stacktrace = com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
	at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112)
	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)
	at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
	at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1045)
	at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:958)
	at com.netflix.discovery.DiscoveryClient.refreshRegistry(DiscoveryClient.java:1475)
	at com.netflix.discovery.DiscoveryClient$CacheRefreshThread.run(DiscoveryClient.java:1442)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1623)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

3、解决办法:在客户端修改

server:
  port: 8082
  servlet:
    context-path: /user
spring:
  application:
    name: userService
eureka:
  client:
    serviceUrl:
      # 给这个地址后面加上/eureka,  不论服务端这块地址是什么,都需要在其后面加上/eureka
      defaultZone: http://localhost:8091/eureka/eureka
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

eureka访问地址:http://localhost:8091/eureka

在这里插入图片描述

此时也就能检测到实例了。

测试了最新版本:

  • Spring Boot:3.2.0
  • Spring Cloud:2023.0.4
  • jdk:20
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/794133
推荐阅读
相关标签
  

闽ICP备14008679号