In a Spring Boot application, the SpringApplication
class automatically supports YAML as an alternative to properties. YAML isn't a markup language. It is an alternative to .properties
files and it allows you to define properties in the hierarchical configuration. The Java parser for YAML is called SnakeYAML. It must be in the classpath, but it is automatically added to the classpath by spring-boot-starters
.
Spring Boot supports YAML for properties as an alternative to properties files. YAML is convenient for hierarchical configuration data. Spring Boot properties are organized in groups, for example, server, database, and so on.
Let's see the following properties:
- In
application.properties
:
database.host = localhost database.user = admin
- In
application.yml
:
database: host: localhost user: admin
Let's see, in the following section, how to define multiple profiles in a single YAML file.