Value Could not resolve placeholder in Spring Boot Test
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The Could not resolve placeholder 'some.property' in value "${some.property}" error in Spring Boot tests means the @Value annotation references a property that is not defined in any property source available to the test context. This happens because test classes use a separate application context that may not load the same property files as the main application. The fix is to provide the property through @TestPropertySource, application-test.properties, or @SpringBootTest(properties = ...).
The Error
The test context cannot find app.api.key in any loaded property file.
Fix 1: @TestPropertySource (Recommended)
Provide test-specific properties directly on the test class:
Properties defined in @TestPropertySource override all other sources, making them ideal for test isolation.
Fix 2: Test Properties File
Create src/test/resources/application-test.properties:
Or use src/test/resources/application.properties (no profile) to override the main application properties for all tests.
Fix 3: @SpringBootTest properties
This is equivalent to @TestPropertySource(properties = ...) but defined on @SpringBootTest itself.
Fix 4: Default Values in @Value
Provide a fallback so the annotation never fails:
The syntax is ${property.name:defaultValue}. The colon separates the property name from the default.
Fix 5: Test Application Properties
Place a file at src/test/resources/application.properties:
Spring Boot's test resource classpath takes priority over main resources.
Understanding Property Source Priority
From highest to lowest priority in tests:
Common Scenarios
Missing Environment Variable
Properties from External Config Server
YAML Properties
If using application.yml, create src/test/resources/application-test.yml:
Slice Tests (@WebMvcTest, @DataJpaTest)
Slice tests load only part of the context, which often means fewer properties are available:
Always provide necessary properties explicitly in slice tests since they do not load the full application context.
Using @MockBean to Avoid Property Issues
If the property is only used by a bean you do not need in the test, mock the bean:
Common Pitfalls
- Typos in property names:
@Value("${app.api-key}")vsapp.api.keyin properties file. Spring Boot relaxed binding convertsapi-keytoapi.key, but@Valuedoes NOT use relaxed binding. Use@ConfigurationPropertiesfor relaxed binding support. - Wrong properties file location:
src/test/resources/application.propertiesis correct.src/test/application.properties(missingresources/) is ignored. - Profile not activated:
application-test.propertiesrequires@ActiveProfiles("test"). Without it, Spring only loadsapplication.properties. - SpEL confusion:
@Value("#{systemProperties['user.home']}")uses SpEL (Spring Expression Language, with#).@Value("${app.key}")uses property placeholder (with$). Mixing them up causes different errors. - Properties in @Configuration classes: If a
@Configurationclass uses@Valueand is loaded in the test context, you must provide those properties even if your test does not directly use them.
Summary
- Use
@TestPropertySource(properties = {"key=value"})for test-specific property overrides - Create
src/test/resources/application-test.propertieswith@ActiveProfiles("test")for shared test properties - Add default values with
@Value("${prop:default}")to prevent failures when properties are optional - Slice tests (
@WebMvcTest,@DataJpaTest) load minimal context, so always provide necessary properties explicitly - Use
@MockBeanto avoid resolving properties for beans you do not need in the test
Related reading
- Verify object attribute value with mockito
- Very slow Spring Boot application startup
- View's getWidth() and getHeight() returns 0
- Virtual Memory Usage from Java under Linux, too much memory used
- Visual Studio 2013 doesn't discover unit tests
- Vowpal Wabbit training and testing data formats
- Value of type 'T' cannot be converted to
- ValueError A Concatenate layer requires inputs with matching shapes except for the concat axis. Got inputs shapes None, 523, 523, 32, etc

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.