Spring Boot Application Configuration with YAML


This guide will introduce you to YAML and the YAML support with the various application configuration options that are present in Spring Boot.

You will learn

  • What is application configuration?
  • What is YAML?
  • What are the advantages of YAML?
  • How do you specify application configuration using YAML with Spring Boot?

Spring Boot Courses

Image

Image

Image

Image

10 Step Reference Courses

YAML is a human readable serialization language

YAML stands for Yet Another Markup Language

Let’s consider an example

application.properties

level1.property1 = 5
level1.property2 = 6
level1.property3 = 7
level1.level2.property4 = 8
level1.level2.property5 = 10
level1.level2.property6 = 11

Above property file is cool but it is not very readable.

Let’s consider the same example in YAML format: application.yaml

level1:
  property1: 5
  property2: 6
  property3: 7
  level2:
     property4: 8
     property5: 10
     property6: 11

YAML

  • is concise
  • is more readable

Spring Boot and YAML

Spring Boot has excellent support for YAML configuration.

Example 1

application.properties

server.port = 9080

application.yaml

server:
	port: 9080

Example 2

application.properties

app.name=in28Minutes
app.description=${app.name} is your first Spring Boot application
welcome.message=Welcome message from property file! Welcome to ${app.name}

application.yaml

app:
   name: In28Minutes
   description: ${app.name} is your first Spring Boot application
welcome:
    message: Welcome to your first Spring Boot app!

Example 3 - Dynamic Configuration

application.properties

basic.value: true
basic.message: Dynamic Message
basic.number: 100

application.yaml

basic: 
   value: true
   message: Dynamic Message YAML
   number: 100

Congratulations! You are reading an article from a series of 50+ articles on Spring Boot and Microservices. We also have 20+ projects on our Github repository. For the complete series of 50+ articles and code examples, click here.

Next Steps

Image

Related Posts

Spring Boot Tutorials for Beginners

At in28Minutes, we are creating a number of tutorials with videos, articles & courses on Spring Boot for Beginners and Experienced Developers. This resources will help you learn and gain expertise at Spring Boot.

Microservices Architectures - What is Fault Tolerance?

In this article, we discuss an important property of microservices, called fault tolerance

Microservices Architectures - Introduction to Auto Scaling

In this article, we focus our attention on the Dynamic Scaling or Auto Scaling. Why do we need applications that can auto scale?

Microservices Architectures - Importance of Centralized Logging

In this article, we explore the concept of centralized logging, in the context of microservices.

Microservices Architectures - Introduction to API Gateway

In this article, we look at what an API Gateway is, in the context of microservices.

Microservices Architectures - Centralized Configuration and Config Server

In this article, we explore the concept of centralized configuration, in the context of microservices.

Microservices Architectures - What is Service Discovery?

In this article, we talk about Service Discovery. Why is Service Discovery important in microservices architecture, and how to set it up for your application.

Microservices Architectures - Advantages Of Microservices

Microservices architectures are very popular today. In this article, we discuss the three main advantages of having a microservices architecture.

Microservice Architectures - Challenges with building Microservices

Microservices architectures are very popular today. In this article, we discuss the important challenges in developing a microservices architecture.

Microservices Architectures - Microservices vs SOA

Microservices architectures are very popular today. In this article, we take a look at how microservices architectures are different from Service Oriented Architectures (SOA).