Springコンフィギュレーションセンター(Spring Cloud Config)はcontext-pathをコンフィギュレーションした後、消費者側がeurekaでコンフィギュレーションを取得できない解決

1717 ワード

最近マイクロサービスを研究して、Eurekaを使って登録センターを建てて、そしてSpringCloudConfigを使って配置センターをします
配置センターが登録センターに登録すると、消費者側はbootstrapにある.ymlは、以下の構成により構成データを取得できます.
spring:
  profiles:
      active: ${#help.profile#:dev}      #       ,      
  cloud:
      config:
        discovery:
          enabled: true
          serviceId: help-config-server
        profile: ${spring.profiles.active}    #              
        name: helpStarter
  application:
    name: help-starter

ただし、コンフィギュレーションセンターにcontext-pathが設定されている場合
server:
  port: 8888
  servlet:
    context-path: /config

その後、正しく取得できなかったが、ログを見ると、消費者側が構成を取得する際にアクセスしたのは127.0であった.0.1:8888、追加/configはありません.後期メンテナンスを考慮すると、URLを書くのは絶対にだめです.長い間資料を調べてから、配置センターのeureka登録部分に以下の配置を追加できることがわかりました.
eureka:
  instance:
    preferIpAddress: true
    health-check-url: http://localhost:${server.port}${server.servlet.context-path:}/actuator/health
    status-page-url: http://localhost:${server.port}${server.servlet.context-path:}/actuator/info
    home-page-url: http://localhost:${server.port}${server.servlet.context-path:}
    metadata-map:
      configPath: ${server.servlet.context-path:}
      management.context-path: ${server.servlet.context-path:}
  client:
    serviceUrl:
      defaultZone: http://127.0.0.1:5000/eureka/

これにより、消費者側で適切な構成情報を取得できます.
ただし、主にcontext-pathを使用しない場合は、servlet全体を「」または注釈するように構成する.context-pathノードは、/に設定するのではなく、消費者側がエラーを報告します.