Brief introduction to bootstrap.yml and application.yml

In the Spring Boot application, the configuration files are either application.properties or application.yml. The application.yml config file will contain application-related configurations, such as server port, JPA configuration, and data source configuration.

In the case of the Spring Cloud application, we need some configurations that would be used in multiple microservices. We require two types of configuration files in the case of the Spring Cloud application. These files are:

  • The Bootstrap application configuration file (bootstrap.yml)
  • The application configuration file (application.yml)

By default, Bootstrap properties are added with high precedence, so they cannot be overridden by local configuration. The bootstrap.yml (or bootstrap.properties) file is loaded before application.yml (or application.properties). The Bootstrap application configuration file is similar to the application.yml file, but it will be loaded at the Bootstrap phase of the application context.

The bootstrap.yml file is typically used for the case of the Spring Cloud Config Server application. You can specify spring.application.name and spring.cloud.config.server.git.uri inside the bootstrap.yml file, as we have seen in the Chapter 4, Getting Started with Spring Cloud and Configuration, and also add some encryption/decryption information. A parent Spring ApplicationContext (known as Bootstrap Application Context) loads the Bootstrap Application configuration file, bootstrap.yml.

The Spring Cloud application usually loads the configuration data from the Spring Cloud Config Server. So, loading the URL and other connection configurations, such as passwords and encryption/decryption information, first we need that Bootstrap configuration. Thus, we have to use the bootstrap.yml file to put in the configurations that are used to load the real configuration data.

Let's see the following example for the bootstrap.yml file:

spring: 
  application: 
    name: foo 
  cloud: 
    config: 
      uri: ${SPRING_CONFIG_URI:http://localhost:8888} 

As you can see in the preceding Bootstrap configuration file, it typically contains two properties, such as the location of the configuration server, spring.cloud.config.uri, and the name of the application, spring.application.name. So, at the startup time of the Spring Cloud application, it makes an HTTP call to load these attributes from the Config Server.

You can disable the Bootstrap process completely by setting spring.cloud.bootstrap.enabled=false.

Let's discuss a simple microservice example in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.177.86