Search code examples
javaspringyamlspring-boot

Spring Boot: how to use multiple yml files


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 {
...

Solution

    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'