Spring Boot - application.yml/application.yaml File

Last Updated : 7 Mar, 2026

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.

ou
Server Configuration

2. Defining the Application Name

We can set a custom name for the Spring Boot application using the spring.application.name property.

ou
Application-Name

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

ou
Data-Base Configuration

For H2 Database

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

ou
H2-Database

For MongoDB Database

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

ou
Mongo-DB

4. Connecting with an Eureka Server

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

ou
Eureka Server

application.yml vs application.properties

Featureapplication.propertiesapplication.yml
FormatKey-value pairsHierarchical
ReadabilityLess readable for large configsMore readable
StructureFlat structureNested structure
UsageSimple configurationComplex configuration
Comment