Spring Boot
application.properties
configuration issue
value not populating
troubleshooting

Spring Boot application.properties @Value not populating

Codemia Knowledge Hub ·

When a value from application.properties (or application.yml) does not populate, the cause is usually a mismatched key, a file Spring Boot is not loading, the wrong active profile, bad placeholder syntax, a missing property, or an environment variable or command-line argument overriding it. Check those in that order.

How Spring Boot resolves properties

Spring Boot resolves values through @ConfigurationProperties, @Value, the Environment and Binder:

  • @Value: Injects a property value into a field, typically with @Value("${property.key}").
  • @ConfigurationProperties: Binds a class to a prefix in the properties file for type-safe config.
  • Profiles: Different configurations per environment, usually in application-{profile}.properties.

Reasons a property is not populated

1. Typo in the property key

The key in application.properties must match exactly what your code references with @Value or @ConfigurationProperties.

2. Property file not loaded

The file might not be loaded, especially if you use spring.config.location or similar mechanisms. Check the project structure and make sure application.properties is under resources:

 
1   src/
2   └── main/
3       ├── java/
4       └── resources/
5           ├── application.properties
6           └── application-dev.properties

3. Wrong active profile

With multiple profiles, make sure the active profile is set correctly:

properties
     spring.profiles.active=dev

Then confirm the matching application-{profile}.properties file is the one being loaded.

4. Placeholder syntax errors

A common mistake is writing ${propertykey} instead of ${property.key}.

5. Property not defined

An unresolved placeholder can mean the property is not defined in the file or the environment. Provide a default value:

java
     @Value("${property.key:defaultValue}")

6. Case sensitivity

Property keys are case-sensitive, so check the casing.

7. Environment overrides

OS environment variables and command-line arguments can override properties. Check whether any are set and causing unexpected values.

Debugging property values

Log the values at startup

Inject the value into a component and log it:

java
1@Component
2public class StartupLogger {
3    @Value("${server.port}")
4    private String serverPort;
5
6    @PostConstruct
7    public void logStartup() {
8        System.out.println("Server Port: " + serverPort);
9    }
10}

If the logged value is null or wrong, check whether it is injected and populated at the right lifecycle stage.

Look for command-line overrides

Command-line arguments take priority over application.properties, so a flag you forgot about will win:

bash
java -jar app.jar --server.port=8081

Example application.properties

properties
1# Application properties
2server.port=8080
3spring.datasource.url=jdbc:mysql://localhost:3306/mydb
4logging.level.org.springframework=DEBUG

Quick reference

Potential IssueDescriptionSolution
Typo in Property KeyThe key is mistyped in code or properties file.Correct by cross-checking property keys.
Incorrect Property FileFile is not in the correct location or not named properly.Confirm file location and name.
Profile MisconfigurationIncorrect profile is active or not set.Set the correct profile using spring.profiles.active.
Syntax ErrorsWrong placeholder syntax.Correct placeholder syntax to ${property.key}.
Property Not DefinedPlaceholder value missing from properties.Define property or provide a default value.
Case SensitivityMismatch in property key casing.Ensure matching casing in properties key and reference.
Environment OverridesEnvironment variables or CLI arguments override properties.Check and adjust CLI arguments/environment settings.

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms