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

查看:40
本文介绍了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.locationspring.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天全站免登陆