Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does spring boot support using both properties and yml files at the same time?

I have a spring boot application and I want to use both a yml file for my application properties and also a plain application-${profile}.properties file set to configure my application.

So my question is can this be done and if so, how do you configure spring boot to look for both the yml file and the properties and merge them into one set per environment?

As to why I want/need to use both, it is because I like the flexibility and ease of use of yml files but an internal component (for encryption) requires using the properties file set.

I did see this point being made YAML files can’t be loaded via the @PropertySource annotation

but nothing stating whether both can be used together.

Please provide detailed configuration (XML or Java config) on how to get this working.

TIA,

Scott

like image 578
Scott C. Avatar asked Aug 10 '14 18:08

Scott C.


People also ask

Does spring boot support using both properties and YAML files at the same time?

Overview. A common practice in Spring Boot is using an external configuration to define our properties. This allows us to use the same application code in different environments. We can use properties files, YAML files, environment variables and command-line arguments.

What is the difference between YAML and properties file in spring boot?

Yaml is yet market language for data serialization format properties files are used for representing key and value simple values. Both are used for configuration files for deployment and application configuration.

Which is a better way to configure a spring boot project using properties or YAML?

If you want to have multiple profiles in your Spring Boot project, by using the YAML file you just need to define one configuration file and put configuration data of specific profile into it, but if you use properties file you need to define individual file for each profile.


1 Answers

I can answer my own question, as it just works as you would expect. The application.yml file and the appropriate application-${profile}.properties both get loaded and merged into the environment. Spring boot just makes this work naturally.

like image 87
Scott C. Avatar answered Oct 15 '22 03:10

Scott C.