Spring Boot
Article 6: Configuration & Properties in Spring Boot
By Utility Zone · 2026-01-27T18:30:29.786091
1. Introduction
Real applications never have hardcoded values.
Things like:
- Server port
- Database URL
- API keys
- Feature flags
must change without changing code.
Spring Boot provides a powerful and clean way to handle configuration.
2. The application.properties File
This is the default configuration file located at:
src/main/resources/application.properties
Example:
server.port=8081
spring.application.name=demo-app
Spring Boot automatically reads this file at startup.
3. Using @Value to Read Properties
3.1 Define a Property
app.message=Hello from properties file
3.2 Inject the Property
@RestController
public class ConfigController {
@Value("${app.message}")
private String message;
@GetMapping("/config-message")
public String getMessage() {
return message;
}
}
Open:
http://localhost:8081/config-message
4. Common application.properties Examples
server.port=8081
logging.level.root=INFO
spring.application.name=my-spring-app
Avoid putting secrets directly here for production.
5. Using application.yml (YAML)
Spring Boot supports YAML as an alternative.
Example:
server:
port: 8081
spring:
application:
name: my-spring-app
✔ Cleaner for large configs
❌ Indentation-sensitive
Choose either .properties or .yml, not both.
6. Configuration Using @ConfigurationProperties
Best for grouped configuration.
6.1 Define Properties
app.name=Demo App
app.version=1.0
6.2 Create Config Class
@Component
@ConfigurationProperties(prefix = "app")
public class AppConfig {
private String name;
private String version;
// getters and setters
}
Spring automatically maps values.
7. Environment-Specific Configuration (Profiles)
Applications behave differently in:
- dev
- test
- prod
Spring Boot supports profiles.
7.1 Create Profile Files
application-dev.properties
application-prod.properties
Example:
server.port=8082
7.2 Activate Profile
spring.profiles.active=dev
Or via command line:
java -jar app.jar --spring.profiles.active=prod
8. External Configuration (Important)
Spring Boot allows config from:
- application files
- Environment variables
- Command-line arguments
Priority:
Command line > Env vars > application.properties
9. Common Configuration Mistakes
❌ Typo in property key
❌ Missing ${} in @Value
❌ Mixing .yml and .properties
❌ Forgetting active profile
10. What You Should Understand Before Moving On
You should now know:
- How Spring Boot reads configuration
- Difference between
.propertiesand.yml - When to use
@Valuevs@ConfigurationProperties - How profiles work
11. What’s Next?
➡ Article 7: Spring Boot + JPA + Hibernate
- Databases
- Entities
- ORM basics
Type Next when you’re ready.