【问题标题】:Spring Boot - ignore application.yml / bootstrap.yml inside .jar fileSpring Boot - 忽略 .jar 文件中的 application.yml / bootstrap.yml
【发布时间】:2018-02-01 23:41:03
【问题描述】:

我有一个使用配置服务器获取配置的 Spring Cloud 应用程序。我们正在使用 Spring Boot 1.5.4 和 Spring Cloud Dalston.SR2

出于部署目的,我们提供外部bootstrap.yml 文件并使用spring.cloud.bootstrap.location 参数指定其位置。

我们已经为几个属性的服务回退到 .jar 的 bootstrap.yml / application.yml 这一事实而苦苦挣扎。

我能找到解决这个问题的唯一方法是使用spring.config.namespring.cloud.bootstrap.name 更改外部配置文件的名称。然后,.jar 中的原始名称将不会被匹配和考虑。

还有其他方法可以解决这个问题吗?

【问题讨论】:

  • 您使用的是什么存储库类型? Git,本地人?您可以提供更多配置吗?版本?
  • 添加了 Spring Boot 和 Cloud 版本。实际上,我们正在使用 MongoDB 后端 - github.com/spring-cloud-incubator/… 的私有分支,它适用于最新的云版本。但是,我添加云使用信息只是因为bootstrap.yml 文件的行为方式与application.yml 相同。即使没有 Spring Cloud,也存在“问题”。我知道该行为遵循规范(扩展配置的属性源顺序 - 15. 应用程序属性打包在您的 jar 中),但它在过去让我们有些头疼。
  • bootstrap.yml 是 spring cloud 的一个特性,所以没有 spring cloud 的 boot 应用永远看不到它,但应该在 jar 中看到 application.yml。
  • 正确,没有云我指的是application.yml。不确定我的意图是否足够清楚 - 让我尝试解释一下:对于 Spring Boot 应用程序(无云)我想指定外部 application.yml 并禁止 Spring Boot 从 jar 文件中解析 yaml(所以它不会是可作为服务应用程序环境中的属性源)。如果 Cloud 到位,我想为 bootstrap.yml 做同样的事情。

标签: spring-boot spring-cloud


【解决方案1】:

您可以通过升级到 Spring Boot 2.x 来解决这个问题,因为它们修复了 spring.config.location 的行为(请参阅 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#configuration-location),这也会以同样的方式影响 spring.cloud.bootstrap.location

另请参阅该问题Different behavior of spring.cloud.bootstrap.location since Spring Boot 2

【讨论】:

  • 你是对的。这就是我们所做的 :) 感谢您回答这个问题 - 我完全忘记了!
猜你喜欢
  • 2016-09-15
  • 2019-10-04
  • 2021-06-28
  • 2016-01-04
  • 1970-01-01
  • 1970-01-01
  • 2018-12-26
  • 2019-04-06
相关资源
最近更新 更多