【问题标题】:Manage property files inside common micro service in Spring Boot在 Spring Boot 中管理公共微服务中的属性文件
【发布时间】:2018-03-31 09:21:40
【问题描述】:

目前我正在从事 Spring Boot 微服务项目。考虑我有 3 个名为 A、B、C 的微服务。现在我的项目为每个微服务分别有 application.yml 文件。现在我想再添加一个微服务 D,用于管理所有服务属性文件。

查看我的配置服务结构

eureka.yml(内部配置服务)文件是:

server: 
  port: 8761
eureka: 
  client:
    registerWithEureka: false
    fetchRegistry: false
  server:
    waitTimeInMsWhenSyncEmpty: 0
endpoints:
  sensitive: false

在 eureka-service bootstrap.properties 中是:

spring:
  application:
    name: eureka
  cloud: 
    config:
      uri: http://localhost:8888

配置服务应用属性:

spring:
  application: 
    name: config 
  cloud: 
    config: 
      server:
        native:
          search-locations: classpath:/config/DEVELOP
  profiles:
     active: native

server:
  port: 8888

我的配置应用程序文件是:

@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }
}

我做了以下步骤:

  1. 启动配置服务
  2. 启动尤里卡服务

不幸的是,eureka 服务器出错了。

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

问题是在运行 eureka 服务器时,它没有查看配置服务中的配置文件...

帮我解决这个问题。或者代替微服务,我怎样才能使用文件夹?

【问题讨论】:

  • 您确定 Eureka 正在从配置服务中获取其属性吗?通常你应该在你的日志中看到这样的内容(在横幅的正下方):[ConfigServicePropertySourceLocator.java:80] - Fetching config from server at: http://localhost:8888。除此之外,请确保您的配置实际可用。您可以通过访问:localhost:8888/eureka 来查看您将在 Eureka 中获得的配置。

标签: java spring-boot microservices netflix-eureka spring-boot-configuration


【解决方案1】:

谢谢@g00glen00b

我将配置服务引导 yml 更改如下:

 spring:
  application: 
    name: config 
  cloud:
    config: 
      server:
        native: 
          searchLocations: classpath:/config/DEVELOP/
  profiles:
     active: native

server:
  port: 8888

它工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-02
    • 2019-01-03
    • 1970-01-01
    • 2017-02-17
    • 2020-05-27
    • 2019-01-19
    • 2015-10-06
    • 2022-01-15
    相关资源
    最近更新 更多