VOOZH about

URL: https://www.geeksforgeeks.org/java/spring-boot-application-yml-application-yaml-file/

⇱ Spring Boot - application.yml/application.yaml File - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Spring Boot - application.yml/application.yaml File

Last Updated : 17 Jun, 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 Spring Boot server port using the server.port property.

  • Changes the application's running port.
  • Default Spring Boot port is 8080.
👁 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.

👁 out

3. Database Configuration

Database connection properties are defined under the spring.datasource section.

  • Stores database URL, username, and password.
  • Supports multiple databases.

For MySQL Database

👁 ou
Data-Base Configuration

For H2 Database

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

  • Mainly used for development and testing.
  • No separate database installation required.
👁 ou
H2-Database

For MongoDB Database

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

  • Configuration placed under spring.data.mongodb.
  • Commonly used in modern microservices.
👁 ou
Mongo-DB

4. Connecting with an Eureka Server

Netflix Eureka acts as a service registry where microservices register themselves. Enables service discovery.

  • Allows dynamic communication between services.
  • Commonly used in Spring Cloud microservices.
👁 ou
Eureka Server

Advantages of application.yml

  • More readable and organized.
  • Supports nested configurations.
  • Reduces duplication of property names.
  • Easier maintenance for large projects.
  • Well-suited for microservices architectures.
  • Simplifies complex configuration management.

application.yml vs application.properties

Featureapplication.propertiesapplication.yml
FormatKey-value pairsHierarchical
ReadabilityLess readable for large configsMore readable
StructureFlat structureNested structure
MaintenanceDifficult for large filesEasier to maintain
UsageSimple configurationComplex configuration
RepetitionMore repetitiveLess repetitive
Comment
Article Tags: