网关服务gateway注册Consul时报错Consul service ids must not be empty

网关服务gateway启动时,初始化Consul相关配置时报错。

java 复制代码
Consul service ids must not be empty, must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen: cbda-server-gateway:10.111.236.142:30857

详细的错误信息如下:

网关gateway的 bootstrap.yml如下:

java 复制代码
spring:
  main:
    allow-bean-definition-overriding: true
  application:
    name: cbda-server-gateway
  cloud:
    consul:
      host: 10.111.236.142
      port: 8500
      config:
        enabled: true #false禁用Consul配置,默认true
        format: YAML    # 表示consul上面文件的格式 有四种 YAML PROPERTIES KEY-VALUE FILES
        data-key: data   #表示consul上面的KEY值(或者说文件的名字) 默认是data
        prefix: config # 设置配置值的基本文件夹
        defaultContext: cbda-server-gateway # 设置所有应用程序使用的文件夹名称
        #profileSeparator # 设置用于使用配置文件在属性源中分隔配置文件名称的分隔符的值
      # 服务发现配置
      discovery:
        # 启用服务发现
        enabled: true
        # 启用服务注册
        register: true
        # 服务停止时取消注册
        deregister: true
        # 表示注册时使用IP而不是hostname
        prefer-ip-address: true
        # 关闭consul健康监测
        register-health-check: true
        # 执行监控检查的频率
        health-check-interval: 30s
        # 设置健康检查失败多长时间后,取消注册
        health-check-critical-timeout: 30s
        # 健康检查的路径
        health-check-path: /soa_actuator/health
        # 服务注册标识,格式为:应用名称+服务器IP+端口
        instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port}

分析:

网关服务gateway在初始化Consul的相关配置时,未读取到ip,导致相关配置类初始化失败,就未能初始化instance-id。修改配置如下:

java 复制代码
spring:
  main:
    allow-bean-definition-overriding: true
  application:
    name: cbda-server-gateway
  cloud:
    consul:
      host: 10.111.236.142
      port: 8500
      config:
        enabled: true #false禁用Consul配置,默认true
        format: YAML    # 表示consul上面文件的格式 有四种 YAML PROPERTIES KEY-VALUE FILES
        data-key: data   #表示consul上面的KEY值(或者说文件的名字) 默认是data
        prefix: config # 设置配置值的基本文件夹
        defaultContext: cbda-server-gateway # 设置所有应用程序使用的文件夹名称
        #profileSeparator # 设置用于使用配置文件在属性源中分隔配置文件名称的分隔符的值
      # 服务发现配置
      discovery:
        # 启用服务发现
        enabled: true
        # 启用服务注册
        register: true
        # 服务停止时取消注册
        deregister: true
        # 表示注册时使用IP而不是hostname
        prefer-ip-address: true
        # 关闭consul健康监测
        register-health-check: true
        # 执行监控检查的频率
        health-check-interval: 30s
        # 设置健康检查失败多长时间后,取消注册
        health-check-critical-timeout: 30s
        # 健康检查的路径
        health-check-path: /soa_actuator/health
        # 服务注册标识,格式为:应用名称+服务器IP+端口
        #instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port}
        instance-id: ${spring.application.name}:${random.value}

最终服务能正常启动。

参考:The Spring Cloud project throws exception when generating document. · Issue #404 · spring-cloud/spring-cloud-consul · GitHub

相关推荐
盟接之桥2 分钟前
盟接之桥说制造:引流品 × 利润品,全球电商平台高效产品组合策略(供讨论)
大数据·linux·服务器·网络·人工智能·制造
Fcy6481 小时前
Linux下 进程(一)(冯诺依曼体系、操作系统、进程基本概念与基本操作)
linux·运维·服务器·进程
袁袁袁袁满1 小时前
Linux怎么查看最新下载的文件
linux·运维·服务器
主机哥哥2 小时前
阿里云OpenClaw部署全攻略,五种方案助你快速部署!
服务器·阿里云·负载均衡
珠海西格电力科技3 小时前
微电网能量平衡理论的实现条件在不同场景下有哪些差异?
运维·服务器·网络·人工智能·云计算·智慧城市
释怀不想释怀3 小时前
Linux环境变量
linux·运维·服务器
zzzsde3 小时前
【Linux】进程(4):进程优先级&&调度队列
linux·运维·服务器
qq_297574674 小时前
Linux 服务器 Java 开发环境搭建保姆级教程
java·linux·服务器
神梦流5 小时前
ops-math 算子库的扩展能力:高精度与复数运算的硬件映射策略
服务器·数据库
神梦流5 小时前
GE 引擎的内存优化终局:静态生命周期分析指导下的内存分配与复用策略
linux·运维·服务器