繁体   English   中英

spring.cloud.config.server.native.search-locations 不适用于 Spring 云配置服务器中的占位符

[英]spring.cloud.config.server.native.search-locations does not work with placeholders in Spring Cloud Config server

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

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

Documentation tells that this can be done using placeholder {application} in search-locations property (according to Spring Cloud Config Server documentation http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_server )。 然而,这并不能解决问题。

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

server:
  port: 8000

spring:
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/configs/{application}

 profiles:
    active: native

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

Skipped config file 'classpath:/configs/{application}/TestApp1-dev.xml' resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.xml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1.xml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.yml' resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.yml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1.yml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.properties' resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.properties' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1.properties' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.yaml' resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.yaml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1.yaml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.xml' resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.xml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application.xml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.yml' resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.yml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application.yml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.properties' resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.properties' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application.properties' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.yaml' resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.yaml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application.yaml' for profile dev resource not found

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

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

我使用里程碑版本的 Spring Cloud Brixton.M5进行了测试,并且搜索位置中的占位符 {application} 按预期工作。

对于 Spring 云版本 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);
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM