【问题标题】:Spring Cloud Config Server configuration with local repository带有本地存储库的 Spring Cloud Config Server 配置
【发布时间】:2019-06-30 14:34:31
【问题描述】:

我正在尝试使用后端存储库(文件系统)设置 Spring Cloud Config Server,但端点(http://localhost:8888/licensingservice/default)返回以下内容:

{"name":"licensingservice","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[]}

主要:

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

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

application.yml:

server:
   port: 8888
spring:
   profiles:
      active: native
    cloud:
       config:
          server:
             native:
                searchLocations: file:///Users/josedavi/Desenvolvimento/WorkSpace/Pessoal/sample-spring-microservices/sample-spring-microservices/config-server/src/main/resources/config

许可服务.yml:

tracer.property: "I AM THE DEFAULT"
spring.jpa.database: "POSTGRESQL"
spring.datasource.platform: "postgres"
spring.jpa.show-sql: "true"
spring.database.driverClassName: "org.postgresql.Driver"
spring.datasource.url: "jdbc:postgresql://database:5432/eagle_eye_local"
spring.datasource.username: "postgres"
spring.datasource.password: "p0stgr@s"
spring.datasource.testWhileIdle: "true"
spring.datasource.validationQuery: "SELECT 1"
spring.jpa.properties.hibernate.dialect: "org.hibernate.dialect.PostgreSQLDialect"

服务配置路径:

C:\Users\josedavi\Desenvolvimento\WorkSpace\Pessoal\sample-spring-microservices\sample-spring-microservices\config-server\src\main\resources\config

项目: https://github.com/jdavid-araujo/sample-spring-microservices

【问题讨论】:

标签: spring spring-boot spring-cloud spring-cloud-config


【解决方案1】:

在配置服务的application.yml 中添加以下格式:

[类路径:/,类路径:/config,类路径:/config/{application},类路径:/config/{application}/{profile}]

上述格式分别从config文件夹、application名称、application名称和profile文件夹中搜索位​​置。

spring:
   profiles:
      active: native
   cloud:
       config:
          server:
             native:
                searchLocations: "[classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]"

【讨论】:

【解决方案2】:

看来问题出在您的searchLocations 属性上。路径必须到达licensingservice 文件夹本身,如果服务器为多个服务提供配置,则必须为每个服务设置路径(以逗号分隔)。

试试这个方法:

...
spring:
  ...
  cloud:
    config:
      server:
        native:
          searchLocations: file:///C:/Users/josedavi/Desenvolvimento/WorkSpace/Pessoal/sample-spring-microservices/sample-spring-microservices/config-server/src/main/resources/config/licensingservice

或者,您可以使用相对路径:

        ...
          searchLocations: classpath:config/licensingservice

另外,如果您正在阅读 Spring Microservices in Action 书籍(第 3 章),您可以查看 source code example 本身。

【讨论】:

    【解决方案3】:

    config server folder structure

    然后在 application.yaml 文件中 云: 配置: 服务器: 本国的: 搜索位置:“[classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]”

    它会完美运行

    【讨论】:

      猜你喜欢
      • 2019-08-11
      • 2021-08-13
      • 2019-12-07
      • 2020-11-13
      • 2021-09-21
      • 2017-06-23
      • 2020-07-23
      • 2016-07-06
      • 2020-06-22
      相关资源
      最近更新 更多