springcloud使用Eureka可能出现Cannot execute request on any known server的解决方法

可能出现的

服务端yml配置
#内置的 tomcat 服务启动监听端口号
server:
  port: 8001
#应用名称
spring:
  application:
    name: EurekaServer01
#EurekaServer 配置
eureka:
  client:
    register-with-eureka: false   #此 EurekaServer 不在注册到其他的注册中心
    fetch-registry: false         #不在从其他中心中心拉取服务器信息
    service-url:
      defaultZone: http://localhost:8001/eureka01/     #注册中心访问地址
客户端yml配置
server:
  port: 9001
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: admin
  application:
    name: UserProvdier01
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8001/eureka01/eureka/

问题:服务端客户端启动正常,客户端连接不了服务端

//出现问题
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

解决方法1

修改服务端yml配置,添加context-path,修改defaultZone
#内置的 tomcat 服务启动监听端口号
server:
  port: 8001
  servlet:
    context-path: /eureka01
#应用名称
spring:
  application:
    name: EurekaServer01
#EurekaServer 配置
eureka:
  client:
    register-with-eureka: false   #此 EurekaServer 不在注册到其他的注册中心
    fetch-registry: false         #不在从其他中心中心拉取服务器信息
    service-url:
      defaultZone: http://localhost:8001/     #注册中心访问地址

解决方法2

修改客户端端yml配置,修改defaultZone
server:
  port: 9001
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: admin
  application:
    name: UserProvdier01
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8001/eureka/

服务端根据yml中配置defaultZone的url不同,浏览器访问路的径也不同,测试ok
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值