Spring Boot: how to use multiple yml files Spring Boot: how to use multiple yml files java java

Spring Boot: how to use multiple yml files


  1. remove @PropertySource annotation, you not need it
  2. rename your scheduling.yml into src/main/resources/application-scheduling.yml
  3. add in src/main/resources/application.yml file next line:

    spring.profiles.include: 'scheduling'


@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).

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.


if I have a lot of configurations and/or environments, usually I do so:

$ cat src/main/resources/application.yml:spring:  profiles:    include: >      profile1,      profile2,      ...      profileN$ ls -lah src/main/resources/config:drwxr-xr-x  4 mak  staff   136B Apr 16 23:58 .drwxr-xr-x  6 mak  staff   204B Apr 17 01:54 ..-rw-r--r--  1 mak  staff    60B Apr 16 23:58 application-profile1.yml-rw-r--r--  1 mak  staff    62B Apr 16 23:16 application-profile2.yml...-rw-r--r--  1 mak  staff    50B Apr 16 23:16 application-profileN.yml