Spring Cloud Discovery Eureka - 返回Localhost而不是它所在的主机名

问题描述 投票:0回答:2

我正在使用Spring Cloud Eureka Server和Config Server作为Discovery First,我的问题是:

当它在eureka服务器中自带的服务注册表时,它返回的Config Server URL是http:// {HOST_NAME}}:8888的http://LOCALHOST:8888 intead,而且其他服务器中托管的所有其他服务都找不到它的配置。

日志行:

从服务器获取配置:http://localhost:8888

我可以做任何配置来解决它吗?

配置服务器的application.yml是这样的:

server:
  port: 8888

spring:
  application:
    name: configserver
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          searchLocations: /opt/config_dir

eureka:
  client:
    serviceUrl:
      defaultZone: http://10.111.22.33:8761/eureka,http://10.111.33.44:8761/eureka

配置客户端bootstrap.yml是这样的:

spring:
  application:
    name: show-service
  profiles:
    active: dev
  cloud:
    discovery:
      enabled: true

eureka:
  client:
    serviceUrl:
      defaultZone: http://10.111.22.33:8761/eureka,http://10.111.33.44:8761/eureka
spring spring-boot spring-cloud spring-cloud-netflix spring-cloud-config
2个回答
1
投票

默认情况下,禁用Discovery First Bootstrap。您在配置客户端应用程序中缺少一些属性 - 使用发现来查找配置服务器URL和配置服务器名称(service-id)。

spring:
  cloud:
    config:
      discovery:
       enabled: true
       service-id: configserver

更多:https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_client.html#discovery-first-bootstrap


0
投票

我通过部署我的项目解决了这个问题 mvn部署 希望这能解决你的问题

© www.soinside.com 2019 - 2024. All rights reserved.