在 spring boot 中将属性放在 application.yml 或 bootstrap.yml 上有什么区别?

新手上路,请多包涵

在 spring boot 中将属性放在 application.yml 或 bootstrap.yml 上有什么区别?在 logging.config 情况下,应用程序的工作方式不同。

原文由 Rys 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 528
2 个回答

我刚刚问了 Spring Cloud 伙计们,我想我应该分享我在这里的信息。

bootstrap.ymlapplication.yml 之前加载。

它通常用于以下情况:

  • 使用 Spring Cloud Config Server 时,应在 — 中指定 spring.application.namespring.cloud.config.server.git.uri bootstrap.yml
  • 一些 encryption/decryption 信息

从技术上讲, bootstrap.yml 由父 Spring ApplicationContext 加载。该父 ApplicationContext 在使用的父级之前加载 application.yml

原文由 Michael Isvy 发布,翻译遵循 CC BY-SA 3.0 许可协议

bootstrap.ymlbootstrap.properties

它仅在您使用 Spring Cloud 并且您的应用程序配置存储在远程配置服务器(例如 Spring Cloud Config Server)上时才使用/需要。

从文档中:

Spring Cloud 应用程序通过创建“引导程序”上下文来运行,它是主应用程序的父上下文。 开箱即用,它负责从外部源加载配置属性,并解密本地外部配置文件中的属性。

请注意, bootstrap.ymlbootstrap.properties 可以 包含其他配置(例如默认值),但通常您只需要将引导配置放在这里。

通常它包含两个属性:

  • 配置服务器的位置( spring.cloud.config.uri
  • 应用程序的名称( spring.application.name

启动时,Spring Cloud 使用应用程序的名称对配置服务器进行 HTTP 调用,并检索回该应用程序的配置。

application.ymlapplication.properties

包含标准应用程序配置 - 通常是默认配置,因为在引导过程中检索到的任何配置都将覆盖此处定义的配置。

原文由 dustin.schultz 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题