Spring配置中心(Spring Cloud Config)在配置了context-path后消费端无法通过eureka获取配置的解决

最近研究微服务,使用Eureka搭建了注册中心,并且使用SpringCloudConfig做配置中心

当配置中心注册到注册中心以后,消费端在bootstrap.yml通过以下配置即可获取到配置数据

server:
  port: 8888
  servlet:
    context-path: /config-server

eureka:
  instance:
    eureka-server-name: localhost
    eureka-server-port: 8761
    metadata-map:
      configPath: ${server.servlet.context-path}
  client:
    serviceUrl:
      defaultZone: http://${eureka.instance.eureka-server-name}:${eureka.instance.eureka-server-port}/eureka-server/eureka/

 以后,却无法正确获取,查看日志发现,消费端在获取配置时,访问的是127.0.0.1:8888,并没有增加/config,考虑到后期维护,写死URL肯定不行,在查阅了很久资料以后才发现,可以在配置中心的eureka注册部分增加如下配置

spring:
  application:
    name: config-client
  cloud:
    config:
      label: master
      profile: dev
#      uri: http://localhost:8888/config-server
      discovery:
        enabled: true              # 表示使用服务发现组件中的Config Server,而不自己指定Config Server的uri,默认false
        service-id: config-server

猜你喜欢

转载自blog.csdn.net/EQuaker/article/details/84379029