Careeroza
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=499YAML
application.yml
spring:
application:
name: shopease
server:
port: 8081
shopease:
currency: INR
free-delivery-above: 499Which One?
| .properties | .yml | |
|---|---|---|
| Syntax | key=value, one per line | indentation-based tree |
| Repetition | prefixes repeated | grouped, less repetition |
| Lists | a.list[0]=x | - x |
| Pitfall | few | indentation 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