Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 { ... 
like image 603
Johan Frick Avatar asked Apr 17 '14 13:04

Johan Frick


People also ask

Can we have multiple YAML files in spring boot?

You can use spring. config. location to specify paths to additional config files as a comma separated list.

Can we have multiple property files in spring boot?

To add different files you can use the spring. config. location properties which takes a comma separated list of property files or file location (directories). The one above will add a directory which will be consulted for application.

Can we have two application properties in spring boot?

Spring Boot supports different properties based on the Spring active profile. For example, we can keep two separate files for development and production to run the Spring Boot application.


1 Answers

  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'

like image 189
Maksim Kostromin Avatar answered Sep 18 '22 01:09

Maksim Kostromin