applicationproperties
application.properties: The Complete Problem-Solver Guide for Spring Boot Developers
application.properties is the default configuration file used by Spring Boot to externalize settings for your application. Whether you're setting database URLs, configuring port numbers, or toggling feature flags, this single file controls how your Spring Boot application behaves at runtime—without requiring code changes.
Key Takeaways
- What it is: A plain-text .properties file placed in
src/main/resources/that Spring Boot reads on startup to configure beans, servers, and data sources. - Why it matters: It eliminates hardcoded values, enables environment-specific configuration, and supports profiles for dev/staging/prod separation.
- Key advantage over alternatives: Simpler syntax than YAML for beginners, native Java Properties support, and direct binding to
@ConfigurationPropertiesbeans. - Common pain points: Property overriding order confusion, missing file errors, profile activation issues, and encoding problems.
- Best practice: Keep sensitive data out of the file entirely—use environment variables or a secrets manager instead.
What Is application.properties?
Definition and Purpose
application.properties is a Java Properties-format configuration file that Spring Boot automatically loads from the classpath at startup. It allows you to override default bean properties and framework settings through simple key-value pairs:
# Server configuration
server.port=8080
# Database configuration
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=admin
spring.datasource.password=secret
# JPA / Hibernate
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
Where Spring Boot Looks for It
Spring Boot searches for application.properties in the following locations, in priority order (highest first):
- A
/configsubdirectory of the current directory - The current directory
- Classpath
/configpackage - Classpath root
This lookup order is critical: files found earlier in the list override those found later, which is the mechanism behind profile-based configuration and deployment-time overrides.
application.properties vs application.yml: Which Should You Use?
One of the most common questions new Spring Boot developers face is whether to use .properties or .yml. Both are fully supported and functionally equivalent at runtime.
| Feature | application.properties | application.yml |
|---|---|---|
| Readability for flat configs | ✅ Superior—linear key-value pairs are easy to scan | ⚠️ Functional but nesting can become visually dense |
| Multi-level configuration | ⚠️ Repetitive prefix (spring.datasource.url) |
✅ Superior—clean nested structure |
| Learning curve | ✅ Minimal—any Java developer understands properties files | ⚠️ Requires understanding of YAML indentation rules |
| IDE auto-completion | ✅ Good—Spring Boot provides extensive property completion | ✅ Good—same Spring Boot metadata support |
| Inline comments | âś… # comment or ! comment |
âś… # comment or // comment |
| Git diff clarity | ✅ Superior—single-line changes are clean | ⚠️ Indentation shifts can create noisy diffs |
| List/multi-value support | ⚠️ my.list=one,two,three (comma-separated) |
âś… - one- two (native YAML lists) |
| Recommended for | Small-to-medium projects, teams new to Spring Boot | Large projects with deeply nested configuration |
How to Create and Load application.properties
Step-by-Step Setup
- Create the file: Add
src/main/resources/application.propertiesin your project structure. - Add properties: Use the
key=valueformat, one per line. - Spring Boot picks it up automatically: No additional configuration is required. The framework scans the classpath and binds properties to beans.
- Run your app: Properties are available immediately via
@Value,@ConfigurationProperties, or theEnvironmentobject.
Verifying That Properties Are Loaded
You can confirm your properties are active by checking the startup log. Spring Boot prints a summary of active profiles and key configurations:
Started MyApplication in 3.2 seconds (JVM running for 4.5)
Tomcat initialized on port(s): 8080 (http)
If no application.properties is found, Spring Boot starts with all defaults—no error is thrown. This silent fallback is a common source of confusion when developers expect a property to have an effect but forget to create the file.
Common Problems and How to Solve Them
Problem 1: "My property value isn't being picked up"
Causes and solutions:
- File not in the right location: Ensure the file is at
src/main/resources/application.propertiesor an overridden path. - Typo in the property key: Property keys are case-sensitive and must match the framework's expected prefix exactly.
- Profile not active: If the property is inside a profile-specific file (
application-dev.properties), the profile must be activated. - Property overwritten later: Check for a second
application.propertiesfurther down the search path that defines the same key.
Problem 2: "How do I manage different environments?"
Solution: Use Spring Profiles. Create profile-specific properties files alongside the base file:
application-dev.properties— local development settingsapplication-staging.properties— staging environmentapplication-prod.properties— production settings
Activate a profile with spring.profiles.active=dev in the base application.properties or via the command line:
java -jar myapp.jar --spring.profiles.active=prod
Profile-specific properties override the base file, so you only need to define values that differ per environment.
Problem 3: "Hardcoded secrets in version control"
Solution: Externalize sensitive properties. Never commit database passwords, API keys, or tokens to application.properties. Instead, use one of these approaches:
- Environment variables: Reference them with
${DB_PASSWORD}syntax in the properties file and supply the actual value at runtime. - Spring Cloud Config: Centralized external configuration server that serves properties per application and profile.
- Kubernetes Secrets / Vault: Inject secrets at deployment time, outside the application package.
- .gitignore the file: Add
application.propertiesto your.gitignoreand distribute a template