This answer was very beautifully explained in the book " Interview Questions on Micro Services for Java Developers (Spring Boot, Spring Cloud, Cloud Native Applications) " by Munish Chandel, version 1.30, 03/25/2018.
The following content has been taken from this book, and the overall merit in this answer belongs to the author of the book, i.e. E. Munish Chandel
application.yml
The application.yml / application.properties file is specific to Spring Boot applications. If you do not change the location of the application’s external properties, spring loading will always load application.yml from the following location:
/src/main/resources/application.yml
You can store all external properties for your application in this file. General properties available in any Spring Boot project can be found at: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html. These properties can be configured as follows. according to your application needs. An example file is shown below:
spring: application: name: foobar data source: driverClassName: com.mysql.jdbc.Driver url: jdbc: mysql: // localhost / test server: port: 9000
bootstrap.yml
On the other hand, the bootstrap.yml file is specific to spring-cloud-config and is loaded before application.yml.
bootstrap.yml is only required if you are using Spring Cloud and your microservice configuration is stored on a remote Spring Cloud Config server.
Important points about bootstrap.yml
- When used with a Spring Cloud Config server, you must specify the application name and location of the git configuration using the following properties.
spring.application.name: "application-name"
spring.cloud.config.server.git.uri: "git-uri-config"
- When used with microservices (except for the cloud configuration server), we need to specify the application name and location of the configuration server using the following properties
spring.application.name:
spring.cloud.config.uri:
- This properties file may contain other configurations related to the Spring Cloud environment, such as the location of the eureka server, properties related to encryption / decryption.
Once launched, Spring Cloud makes an HTTP (S) call to the Spring Cloud Config server with the application name and returns the configuration of these applications.
application.yml contains the default configuration for the microservice, and any configuration received (from the cloud configuration server) during the boot process will override the configuration defined in application.yml
Vaibhav Sharma 04 Oct '18 at 9:51 2018-10-04 09:51
source share