What is the difference between putting a property on application.yml or bootstrap.yml in spring boot? In logging.config case, the application works different.
Although both of them share the same Environment, they have different conventions for locating the external configuration files. The bootstrap context is searching for a bootstrap. properties or a bootstrap. yaml file, whereas the application context is searching for an application.
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.
As well as Java properties files, we can also use YAML-based configuration files in our Spring Boot application. YAML is a convenient format for specifying hierarchical configuration data. This can be more readable than its property file alternative since it does not contain repeated prefixes.
I have just asked the Spring Cloud
guys and thought I should share the info I have here.
bootstrap.yml
is loaded before application.yml
.
It is typically used for the following:
spring.application.name
and spring.cloud.config.server.git.uri
inside bootstrap.yml
encryption/decryption
informationTechnically, bootstrap.yml
is loaded by a parent Spring ApplicationContext
. That parent ApplicationContext
is loaded before the one that uses application.yml
.
bootstrap.yml
or bootstrap.properties
It's only used/needed if you're using Spring Cloud and your application's configuration is stored on a remote configuration server (e.g. Spring Cloud Config Server).
From the documentation:
A Spring Cloud application operates by creating a "bootstrap" context, which is a parent context for the main application. Out of the box it is responsible for loading configuration properties from the external sources, and also decrypting properties in the local external configuration files.
Note that the bootstrap.yml
or bootstrap.properties
can contain additional configuration (e.g. defaults) but generally you only need to put bootstrap config here.
Typically it contains two properties:
spring.cloud.config.uri
)spring.application.name
)Upon startup, Spring Cloud makes an HTTP call to the config server with the name of the application and retrieves back that application's configuration.
application.yml
or application.properties
Contains standard application configuration - typically default configuration since any configuration retrieved during the bootstrap process will override configuration defined here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With