spring boot:将新的 yml 文件添加到应用程序配置 [英] spring boot: add new yml files to application config

查看:89
本文介绍了spring boot:将新的 yml 文件添加到应用程序配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望开发人员能够在本地覆盖一些配置属性.(假设我们在谷歌驱动器上工作,每个人都应该用自己的帐户测试它).我不想使用命令行覆盖属性(因为它必须在每个 IDE 配置和每次 CLI 运行时设置).

i want developers to be able to locally override some configuration properties. (let's say we work on google drive and everyone should test it on its own account). i don't want to override properties using command line (because it has to be set inside every IDE configuration and on every CLI run).

我想要的是:应用程序应该使用所有标准的 Spring Boot 配置文件(application.yml 等),并寻找例如local.yml(在类路径上)或 ​​user.home 中的一些文件.并且这些附加文件应该覆盖其他设置.

what i want is: application should use all the standard spring boot config files (application.yml etc) and also look for e.g. local.yml (on the classpath) or some file inside user.home. and those additional files should override other settings.

如何添加新的yml资源并正确排序?

how to add new yml resources and order them correctly?

我知道 spring 的默认订单和位置.问题是关于添加

edit: i know spring's default orders and locations. question is about adding new ones

推荐答案

如果您查看 Spring Boot 文档中有关配置文件位置的信息 (http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config),您可以看到,它们是从以下位置(以及其他位置)加载的:

If you look in the Spring Boot documentation about the locations for configuration files (http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config), you can see, that they are loaded from the following places (amongst others):

  • 打包 jar 之外的特定于配置文件的应用程序属性(application-{profile}.properties 和 YAML 变体)
  • 打包 jar 之外的应用程序属性(application.properties 和 YAML 变体).

加载它们的默认位置有两个(参见 http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-application-property-files):

There are two default locations where they are loaded from ( see http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-application-property-files):

  • 当前目录的/config 子目录.
  • 当前目录

本例中的当前目录是指Java进程的工作目录(通常是JAR所在的目录,或者在IDE中运行的情况下,通常是项目根文件夹).因此,开发人员只需将他们自己的配置文件放在那些地方,它们就会被自动加载(并将覆盖 JAR 中的属性).将这些文件添加到 .gitignore(或 .svnignore 或 ...),它们就不会意外提交到您的存储库中.

Current directory in this case means the working directory for the Java process (Usually the directory where the JAR is located, or in case of running with in the IDE, usually the project root folder). So the developers just can place their own configuration files in that places and they are automatically loaded (and will override properties within the JARs). Add that files to .gitignore (or .svnignore or ...) and they won't accidentally committed into your repository.

这篇关于spring boot:将新的 yml 文件添加到应用程序配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆