When I started learning about Spring Boot, I usually saw examples using application.properties/application.yml and bootstrap.properties/bootstrap.yml. Then this was confusing my head. Let’s see the case where each one should be used.
bootstrap.properties
The bootstrap.properties/bootstrap.yml is a specific file from Spring Cloud and it’s loaded before the application.properties/application.yml. Important properties like spring.application.name
and spring.cloud.config.server.git.uri
goes into bootstrap file. Also encryption/decryption information. See below an example of a bootstrap.yml:
spring:
application:
name: organizationservice
profiles:
active:
default
cloud:
config:
enabled: true
server:
port: 8081
In the example above, the properties defined are:
spring.application.name = organizationservice
this property is responsible for setting the application namespring.profile.active = default
this property sets the profile defined in the config serverspring.cloud.config.enabled = true
this property is enabling the application to connect to the config serverspring.server.port = 8081
here the port for the application is being defined
application.properties
The application.properties/application.yml is a common file to Spring Boot applications. In this file also goes important properties, but the main difference is the precedence, since bootstrap.properties/bootstrap.yml has a higher priority. See below an example of an application.yml:
eureka:
instance:
preferIpAddress: true
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
In the above example, the properties defined are:
eureka.instance.preferIpAddress = true
this property informs Eureka service that the client wants to be advertised by IP address instead of DNSeureka.client.registerWithEureka = true
this property tells the application to register with Eurekaeureka.client.fetchRegistry = true
is used to tell the Spring Eureka Client to fetch a local copy of the registryeureka.client.serviceUrl.defaultZone = http://localhost:8761/eureka
this comma separated attribute is used to inform the list of urls of the Eureka Service
Hope you enjoyed this post and see you soon!
For more information about this Spring Boot configuration access here . If you want to check all Spring Boot common properties go here
Be First to Comment