Spring Boot lets you configure your app without touching code by using configuration files. These files live in the src/main/resources folder and help control:
- Server port
- Database settings
- Logging levels
- Custom application properties
The two most commonly used Spring Boot Properties formats are:
application.propertiesapplication.yml
Letβs explore how they differ and how to use them effectively.

π What is application.properties?
A simple key-value file format used for defining configuration.
π§ Example:
server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.username=root
spring.datasource.password=secret
logging.level.org.springframework=DEBUG
β Pros:
- Simple to read/write for small apps
- Easy to grep or parse
- Familiar for traditional Java devs
π What is application.yml?
YAML (YAML Ainβt Markup Language) is a structured, hierarchical configuration format.
π§ Same Example in YAML:
server:
port: 8081
spring:
datasource:
url: jdbc:mysql://localhost:3306/testdb
username: root
password: secret
logging:
level:
org:
springframework: DEBUG
β Pros:
- Better for complex/nested properties
- More readable for large configs
- Preferred in Kubernetes and cloud-native apps
π Key Differences
| Feature | application.properties | application.yml |
|---|---|---|
| Format | Key-Value | Hierarchical (YAML) |
| Readability | Good for small configs | Better for structured configs |
| Multi-profile support | Slightly verbose | Cleaner with nesting |
| Error sensitivity | Fewer formatting errors | Sensitive to indentation |
| Community trend | Older Spring projects | Increasingly popular |
π― When to Use Which?
- Use
application.propertiesif: - Use
application.ymlif:
β Both formats are fully supported by Spring Boot β itβs a matter of preference.
π₯ Multi-Profile Support
You can create profile-specific files like:
application-dev.propertiesapplication-prod.yml
Activate a profile via:
spring.profiles.active=dev
Or use --spring.profiles.active=prod when starting your app.
π Accessing Custom Properties
Example:
app:
welcome: Hello from YAML!
You can bind this to a class:
@Component
@ConfigurationProperties(prefix = "app")
public class AppProperties {
private String welcome;
// Getter and Setter
}
Make sure you add:
@EnableConfigurationProperties(AppProperties.class)
π« Common Mistakes to Avoid
| Mistake | Problem |
|---|---|
| Indentation error in YAML | Causes app to fail silently or misread properties |
Mixing application.yml and .properties unintentionally | May lead to confusion if overlapping values |
| Not setting active profile | Spring uses default profile, might load wrong config |
| Hardcoding sensitive values | Use environment variables or vaults for secrets |
β Summary
| Topic | Key Takeaway |
|---|---|
| Properties vs YAML | Choose based on readability and structure |
| Profiles | Use application-{profile}.yml/properties |
| Accessing custom values | Use @ConfigurationProperties |
| Security | Avoid storing secrets directly |
Whether you choose .properties or .yml, Spring Boot Properties gives you the power to tweak your app without touching the code.