1. Overview

In this tutorial, we’ll learn how to convert the default application.properties file we receive when we download a new Spring Boot project from Spring Initializer to the more readable application.yml file.

2. Difference Between Properties and YML File

Before diving directly into the topic, let’s see the difference between these two file formats in the form of code.

In the application.properties file, properties are stored as a single-line configuration. Spring Boot generates the properties file as the default one:

spring.datasource.url=jdbc:h2:mem:testDB
spring.datasource.username=user
spring.datasource.password=testpwd

On the other hand, we can create an application.yml. This is a YML-based file that is easy to read when having hierarchical data compared to the properties file:

spring:
  datasource:
    url: jdbc:h2:mem:testDB
    username: user
    password: testpwd

As we can see, with the help of YML-based configuration, we have removed the need to add repeated prefixes (spring.datasource).

3. Convert Properties to YML and Vice-Versa

3.1. IntelliJ Plugin

If we’re using IntelliJ as our IDE to run the Spring Boot application, we can do the conversion by installing the following plugin:

Properties-To-YML-Intellij

We need to go to File > Settings > Plugins > Install “Convert YAML and Properties file”.

Once we’ve installed the plugin, we:

  • Right-click on the application.properties file
  • Select the option “Convert YAML and Properties file” to convert the file to application.yml automatically

We’ll be able to convert it back as well.

3.2. Online Website Tool

Instead of installing plugins, we can also directly copy-paste the config from our codebase to the Mageddo converter website.

For security purposes, ensure we don’t enter passwords for conversion on third-party websites:Mageddo-Properties-To-YML

We put the code in the respective properties/YML section and converted it into another format.

4. Conclusion

In this tutorial, we’ve seen the difference between .properties and .yml files and learned how to convert the application.properties file to application.yml and vice-versa using various tools and plugins highlighted.