In Spring Boot applications, configuration is used to control application behavior without changing the source code. Along with application.properties, Spring Boot also supports application.yml or application.yaml for defining configuration settings.
- YAML configuration files allow developers to organize settings in a hierarchical and readable format.
- They are commonly used to configure properties such as server settings, database connections, logging levels, and microservice configurations.
Why Use application.yml?
- Provides a structured and hierarchical configuration format.
- More readable for complex configurations.
- Reduces repetition compared to application.properties.
- Widely used in microservices and cloud-based Spring Boot applications.
Common Configuration Examples
1. Server Configuration
We can change the default port (8080) of a Spring Boot application using the server.port property in the application.yml file.

2. Defining the Application Name
We can set a custom name for the Spring Boot application using the spring.application.name property.

This represents a key-value configuration, where properties are defined in a hierarchical structure.
3. Database Configuration
To connect a Spring Boot application with a database, we define properties related to the datasource.
For MySQL Database

For H2 Database
H2 Database is an in-memory database commonly used for development and testing.

For MongoDB Database
To connect with MongoDB, we define properties under spring.data.mongodb.

4. Connecting with an Eureka Server
Netflix Eureka acts as a service registry in microservices architecture. Each microservice registers itself with the Eureka server.

application.yml vs application.properties
| Feature | application.properties | application.yml |
|---|---|---|
| Format | Key-value pairs | Hierarchical |
| Readability | Less readable for large configs | More readable |
| Structure | Flat structure | Nested structure |
| Usage | Simple configuration | Complex configuration |