当前位置: 首页 > 知识库问答 >
问题:

Spring云配置。服务器出生地的搜索位置不适用于Spring Cloud Config server中的占位符

麹耘豪
2023-03-14

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

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

文档告诉我们,这可以使用搜索位置属性中的占位符{应用程序}来完成(根据Spring Cloud Config Server留档http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_server)。然而,这并没有做到这一点。

我在应用程序中有以下配置。配置服务器的yml

server:
  port: 8000

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

 profiles:
    active: native

当我向endpoint发出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源代码,但在SearchLocations属性中似乎没有替换占位符。嗯,我也有可能错过了/误解了什么:)

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

共有1个答案

呼延俊风
2023-03-14

我用SpringCloudBrixton的里程碑版本做了一个测试。搜索位置中的M5和占位符{application}按预期工作。

 类似资料:
  • 我用Spring Boot开发了一个微服务。此服务正在使用Spring云配置服务器获取属性。此微服务接受标头中的版本,并根据版本执行相应的功能。在我的github repo中,我有2个分支,每个版本1个。该服务通常将以下信息发送到配置服务器以获取属性- 应用程序名称配置文件标签 是否有办法在my中使用占位符代替标签。yml文件?如果我在标题else v2中看到v1,我希望将标签动态设置为v1。 编

  • 我正在为一个中国客户创建一个Android应用程序,他们需要地图集成,所以谷歌地图不是一个选项,因为所有谷歌服务在中国都被屏蔽了。我正在尝试使用百度地图,它被称为百度LBS(基于位置的服务)云。 获得一个没有覆盖的基本地图相对容易。过程在这里描述(中文,但如果你不懂语言,代码不言自明)。下载最新的百度AndroidSDK(在撰写本文时为v3.2.0)并将其作为库集成到我的Eclipse项目中没问题

  • 我正在使用Spring Cloud Config服务器,能够检测来自git存储库的更改并将其传递给配置客户机。 有两种方法,我已经实现了: null 所以两者都工作得很好,那么使用Spring Cloud Bus有什么好处吗?或者在生产环境中,不使用Spring Cloud Bus会有什么问题吗?因为将需要额外的工作来设置RabbitMQ集群(HA)作为生产中的Spring云总线。 谢谢,大卫

  • 问题内容: 我打开控制台(chrome \ firefox)并运行以下行: 内容未包含在#popupFrame中,这使它变得很奇怪。 目标是创建像firefox这样的警告框 问题答案: 第二个div是(默认值),因此z-index不适用于它。 您需要定位(将位置属性设置为,而不是在这种情况下可能需要的其他位置)要分配给的任何内容。

  • 我试图初始化log4j记录器使用SpringIOC和使用财产onfigurator.configure配置记录器,但财产onfigurator.configure不工作。 我的问题是如何将配置(log4j.properties)传递给Logger类? 波姆。xml 混淆班 log4j。性质