YAML stands for YAML Ain’t Markup Language

YAML is built from the ground up to be simple to use. At its core, a YAML file is used to describe data. One of the benefits of using YAML is that the information in a single YAML file can be easily translated to multiple language types.

Click here to learn more about YAML.

Spring Boot YAML Configuration

The SpringApplication class by default supports YAML as an alternative to properties whenever you have the SnakeYAML library on your classpath.

If you use “Starters”, SnakeYAML is automatically provided by spring-boot-starter.

  • YAML files should end in .yaml or .yml
  • YAML is case sensitive.
  • YAML does not allow the use of tabs. Spaces are used instead as tabs are not universally supported.

Loading YAML Instead of Properties file

Spring Framework provides two convenient classes that can be used to load YAML documents. The YamlPropertiesFactoryBean loads YAML as Properties and the YamlMapFactoryBean loads YAML as a Map.

For example, consider the following YAML document:

  name: TalksInfo
  url: https://talksinfo.com
    - Maven
    - Spring Boot
    - Core Java
    - Design Patterns

The preceding example would be transformed into the following properties:

app.topics[1]=Spring Boot
app.topics[2]=Core Java
app.topics[3]=Design Patterns

YAML lists are represented as property keys with [index] dereferencers. For example, consider the following YAML:

    - Maven
    - Spring Boot
    - Core Java
    - Design Patterns

Example Project using Spring Boot YAML

Create a new Spring Starter Project and project’s folder structure as follows,

YAML Project Structure


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <relativePath/> <!-- lookup parent from repository -->
  <description>Demo project for Spring Properties file</description>







  name: TalksInfo
  url: https://talksinfo.com
    - Maven
    - Spring Boot
    - Core Java
    - Design Patterns


public class ApplicationProperties {
  private App app;
  public void setApp(App app) {
    this.app = app;

  public static class App{
    private String name;
    private String url;
    private List<String> topics;
    public String getName() {
      return name;
    public void setName(String name) {
      this.name = name;
    public String getUrl() {
      return url;
    public void setUrl(String url) {
      this.url = url;
    public List<String> getTopics() {
      return topics;
    public void setTopics(List<String> topics) {
      this.topics = topics;

  public App getApp() {
    return app;

The annotation used here are:

  • @Configuration marks the class as a source of bean definitions
  • @ConfigurationProperties binds and validates the external configurations to a configuration class
  • @EnableConfigurationProperties this annotation is used to enable @ConfigurationProperties annotated beans in the Spring application


public class SpringYamlApplication implements ApplicationRunner{
  private Logger LOG = LoggerFactory.getLogger(SpringYamlApplication.class);

  private ApplicationProperties appProperties;
  public static void main(String[] args) {
    SpringApplication.run(SpringYamlApplication.class, args);
  public void run(ApplicationArguments args) throws Exception {



[Maven, Spring Boot, Core Java, Design Patterns]

When binding to Map properties, if the key contains anything other than lowercase alpha-numeric characters or -, you need to use the bracket notation so that the original value is preserved. If the key is not surrounded by [], any characters that are not alpha-numeric or - are removed. For example, consider binding the following properties to a Map:

    "[/key1]": value1
    "[/key2]": value2
    /key3: value3

The properties above will bind to a Map with /key1/key2 and key3 as the keys in the map.


In this quick article, we have seen how to use YAML in spring boot and how to replace application.properties file using YAML file. Also, usage of List, Arrays, Map in YAML is given an introduction.