Spring Boot:如何使用多个yml文件 [英] Spring Boot: how to use multiple yml files

查看:456
本文介绍了Spring Boot:如何使用多个yml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring Boot中,我知道我可以用application.yml替换application.properties并使用YAML格式。
然而,我的application.yml变得拥挤,所以我需要将它分开一点。我怎样才能做到这一点?我想做这样的事情:

In Spring Boot, I know that I can replace application.properties with application.yml and use the YAML format. However, my application.yml is getting crowded so I need to split it up a bit. How can I do that? I would like to do something like this:

...
@Configuration
@EnableAutoConfiguration
@EnableWebMvc
@EnableScheduling
@PropertySource({"classpath:application.yml", "classpath:scheduling.yml"})
public class ApplicationConfig {
...


推荐答案

@PropertySource 不支持YAML(可能会在Spring 4.1中使用)。您可以将 spring.config.location spring.config.name 设置为以逗号分隔的列表(例如,作为系统属性或命令行参数)。

@PropertySource does not support YAML (probably it will in Spring 4.1). You can set spring.config.location or spring.config.name to a comma-separated list (e.g. as System property or command line argument).

我个人喜欢在同一个地方放置所有的YAML(结构真的有助于在视觉上分解它,你可以使用里面的文件文件将其拆分更多)。我觉得这只是味道。

Personally I like all my YAML in the same place (the structure really helps to break it up visually, and you can use documents inside the file to split it up more). That's just taste I guess.

这篇关于Spring Boot:如何使用多个yml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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