Multiple profiles inside a single YAML file

A YAML file can contain configuration for multiple profiles. You can define multiple profile-specific configurations in a single YAML file. Spring Boot provides a spring.profiles key to indicate when the document applies. Let's see the following example of how to define multiple profile-specific configurations in a single YAML file:

 
#Used for all profiles 
 
logging.level: 
org.springframework: INFO 
 
#'dev' profile only 
--- 
 
spring.profiles: dev 
database: 
   host: localhost 
   user: dev 
 
#'prod' profile only 
 
--- 
 
spring.profiles: prod 
database: 
   host: 192.168.200.109 
   user: admin 

In this application.yml file, we have defined database settings according to two profiles, dev and prod, by using a spring.profile ...

Get Mastering Spring Boot 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.