【问题标题】:spring.cloud.config.server.native.search-locations does not work with placeholders in Spring Cloud Config serverspring.cloud.config.server.native.search-locations 不适用于 Spring Cloud Config 服务器中的占位符
【发布时间】:2016-07-09 11:04:27
【问题描述】:

我使用文件系统后端 (spring.profiles.active=native) 来加载配置文件。

我想要实现的是每个应用程序都有一个单独的文件夹,其中存储了适当组件的所有配置,例如/configs/TestApp1/*.yml, /configs/TestApp2/*.yml

文档告诉我们可以使用 search-locations 属性中的占位符 {application} 来完成(根据 Spring Cloud Config Server 文档http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_server)。然而这并不能解决问题。

我在配置服务器的 application.yml 中有以下配置

服务器: 端口:8000 春天: 云: 配置: 服务器: 本国的: 搜索位置:类路径:/configs/{application} 简介: 活跃:原生

当我向端点发出 HTTP GET 请求时:http://localhost:8000/TestApp1/dev 我没有从配置服务器获取配置,因为它不会将占位符替换为客户端应用程序名称(至少我认为它应该以这种方式工作)并尝试查看在以下目录中:

未找到跳过的配置文件“类路径:/configs/{application}/TestApp1-dev.xml”资源 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/TestApp1-dev.xml' 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/TestApp1.xml' 未找到跳过的配置文件“类路径:/configs/{application}/TestApp1-dev.yml”资源 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/TestApp1-dev.yml' 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/TestApp1.yml' 未找到跳过的配置文件“类路径:/configs/{application}/TestApp1-dev.properties”资源 未找到配置文件开发资源的跳过配置文件“类路径:/configs/{application}/TestApp1-dev.properties” 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/TestApp1.properties' 未找到跳过的配置文件“类路径:/configs/{application}/TestApp1-dev.yaml”资源 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/TestApp1-dev.yaml' 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/TestApp1.yaml' 未找到跳过的配置文件“类路径:/configs/{application}/application-dev.xml”资源 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/application-dev.xml' 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/application.xml' 未找到跳过的配置文件“类路径:/configs/{application}/application-dev.yml”资源 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/application-dev.yml' 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/application.yml' 未找到跳过的配置文件“类路径:/configs/{application}/application-dev.properties”资源 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/application-dev.properties' 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/application.properties' 未找到跳过的配置文件“classpath:/configs/{application}/application-dev.yaml”资源 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/application-dev.yaml' 未找到配置文件开发资源的跳过配置文件 'classpath:/configs/{application}/application.yaml'

注意:我尝试调试 Spring 源代码,但 search-locations 属性中的占位符似乎没有被替换。好吧,我也有可能错过/误解了一些东西:)

也许有人可以建议我如何在 Spring Cloud Config Server 中为每个应用程序设置单独的配置目录?

【问题讨论】:

  • 你用的是什么版本?
  • 我正在使用 Angel.SR4 (spring-cloud-parent - 1.0.3.RELEASE, spring-boot-starter-parent - 1.2.6.RELEASE)
  • 我对 Angel.SR6 版本进行了快速检查(spring-cloud-parent - 1.0.4.RELEASE,spring-boot-starter-parent - 1.2.8.RELEASE),但仍然没有运气让它工作。
  • 此功能在 Brixton.M5 上正常工作。
  • 是的,这是 Brixton 的新功能。

标签: java spring spring-boot spring-cloud


【解决方案1】:

我对 Spring Cloud Brixton.M5 的里程碑版本进行了测试,搜索位置中的占位符 {application} 工作正常。

【讨论】:

    【解决方案2】:

    使用 Spring Cloud 版本 2021.0.0,使用 searchLocations

    spring:
      application:
        name: config-service
      profiles:
        active: native
      cloud:
        config:
          server:
            native:
              searchLocations: classpath:/config
    
    server:
      port: 8888
    

    确保您在主应用程序中使用@EnableConfigServer 注解。

    例如

    @SpringBootApplication
    @EnableConfigServer
    public class ConfigurationServerApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(ConfigurationServerApplication.class, args);
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-22
      • 2017-05-01
      • 2019-01-12
      • 2020-10-05
      • 2017-08-17
      • 2018-11-10
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      相关资源
      最近更新 更多