Properties vs YAML

Two Formats, Same Settings

Spring Boot reads settings from src/main/resources/application.properties or application.yml. Use one format per project.

Properties

application.properties

spring.application.name=shopease
server.port=8081
shopease.currency=INR
shopease.free-delivery-above=499

YAML

application.yml

spring:
  application:
    name: shopease
server:
  port: 8081
shopease:
  currency: INR
  free-delivery-above: 499

Which One?

.properties.yml
Syntaxkey=value, one per lineindentation-based tree
Repetitionprefixes repeatedgrouped, less repetition
Listsa.list[0]=x- x
Pitfallfewindentation must be spaces; a wrong indent silently changes meaning

Tip: Most teams use YAML for bigger configs. IntelliJ and VS Code (Spring Boot extension) autocomplete both and warn about unknown keys.

How Spring Reads Properties

Example

A .properties file is just key-value text. Java can read it with java.util.Properties, which is roughly the first step Spring does:

import java.io.StringReader;
import java.util.Properties;

public class Main {
    public static void main(String[] args) throws Exception {
        String file = """
            # ShopEase settings
            spring.application.name=shopease
            server.port=8081
            shopease.currency=INR
            shopease.free-delivery-above=499
            """;

        Properties props = new Properties();
        props.load(new StringReader(file));

        int port = Integer.parseInt(props.getProperty("server.port", "8080"));
        int freeAbove = Integer.parseInt(props.getProperty("shopease.free-delivery-above"));
        String timezone = props.getProperty("shopease.timezone", "Asia/Kolkata");   // missing -> default

        System.out.println("App      : " + props.getProperty("spring.application.name"));
        System.out.println("Port     : " + port);
        System.out.println("Currency : " + props.getProperty("shopease.currency"));
        System.out.println("Free delivery above Rs." + freeAbove);
        System.out.println("Timezone : " + timezone);
    }
}

Output

App      : shopease
Port     : 8081
Currency : INR
Free delivery above Rs.499
Timezone : Asia/Kolkata