Last updated : August 4, 2026

YAML Configuration Tutorials

Web Development

Spring Boot application.yml / application.yaml

1. Introduction

Spring Boot supports configuration using:

YAML files are used to define configuration in a structured and readable format.

2. Why Use application.yml

  • Hierarchical structure

  • Easy to read

  • Less repetition

  • Better for large applications

  • Common in microservices

3. File Location

plaintext

src/main/resources

4. Server Configuration

Change default port:

plaintext

server:
  port: 8989

5. Application Name

plaintext

spring:
  application:
    name: my-app

6. Database Configuration

MySQL Example

plaintext

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mydb
    username: root
    password: 1234
    driver-class-name: com.mysql.cj.jdbc.Driver

H2 Database Example

plaintext

spring:
  datasource:
    url: jdbc:h2:mem:testdb
    username: sa
    password: ""
  h2:
    console:
      enabled: true

MongoDB Example

plaintext

spring:
  data:
    mongodb:
      uri: mongodb://localhost:27017/mydb

7. Eureka Server Configuration

plaintext

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
    register-with-eureka: true
    fetch-registry: true

8. application.yml vs application.properties

Format

  • properties: key=value

  • yaml: hierarchical

Readability

  • properties: less readable for large config

  • yaml: more readable

Structure

  • properties: flat

  • yaml: nested

Usage

  • properties: simple configuration

  • yaml: complex configuration

9. Key Points

  • YAML uses indentation

  • No semicolons or brackets

  • Better for complex setups

  • Widely used in microservices

10. Conclusion

  • application.yml is modern and readable

  • Preferred for large applications

  • Helps organize configuration clearly

Job PortalJobs