我使用文件系统后端( spring.profiles.active = native )来加载配置文件。
我想要实现的是每个应用程序都有单独的文件夹,其中存储了适当组件的所有配置,例如: /configs/TestApp1/*.yml,/ configs / TestApp2 / *。yml
文档说明可以使用搜索位置属性中的占位符 {application} 来完成此操作(根据Spring Cloud Config Server文档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 Cloud Config Server中为每个应用程序设置单独的配置目录?
答案 0 :(得分:0)
我使用里程碑版的Spring Cloud Brixton.M5 进行了测试,搜索位置的占位符{application}正在按预期工作。