Yml配置文件“继承"使用Spring Boot [英] Yml config files "Inheritance" with Spring boot

查看:785
本文介绍了Yml配置文件“继承"使用Spring Boot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上找不到直接的答案.

I couldn't find a straight answer online.

Spring Boot的yml文件是否彼此继承"?我的意思是,如果我有: application.yml具有

Do Spring Boot's yml files "inherit" from each other? I mean if I have: application.yml which has

server:
  port: 80
  host: foo

application-profile1.yml仅具有

server:
  port: 90

因此,如果我以profile1作为活动配置文件启动Spring Boot,我还将server.host属性设置为foo吗?

So if I start my Spring Boot with profile1 as active profile, will I also have server.host property set to foo?

推荐答案

是的,application.yml文件的优先级高于任何application-{profile}.yml文件.特定于配置文件的yml文件中的属性将覆盖默认application.yml文件中的值,而特定于配置文件的yml文件中不存在的属性将从默认文件中加载.它适用于.properties文件以及bootstrap.ymlbootstrap.properties.

Yes, application.yml file has higher precedence over any application-{profile}.yml file. Properties from profile specific yml file will override values from the default application.yml file and properties that do not exist in profile specific yml file will be loaded from the default one. It applies to .properties files as well as to bootstrap.yml or bootstrap.properties.

Spring Boot文档在 72.7根据环境更改配置 段落:

Spring Boot documentation mentions it in 72.7 Change configuration depending on the environment paragraph:

在此示例中,默认端口为9000,但如果Spring概要文件开发"处于活动状态,则该端口为9001,如果生产"为活动,则其为0.

In this example the default port is 9000, but if the Spring profile ‘development’ is active then the port is 9001, and if ‘production’ is active then it is 0.

YAML文档按照它们遇到的顺序进行合并(因此,较新的值将覆盖较早的值).

The YAML documents are merged in the order they are encountered (so later values override earlier ones).

要对属性文件执行相同的操作,可以使用application-${profile}.properties指定特定于配置文件的值.

To do the same thing with properties files you can use application-${profile}.properties to specify profile-specific values.

这篇关于Yml配置文件“继承"使用Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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