Let's get started with a Microservice Architecture with Spring Cloud:
Resolving Spring Boot Exception: The Elements Were Left Unbound
Last updated: March 26, 2026
1. Overview
Spring Boot provides powerful configuration binding through @ConfigurationProperties. While this feature simplifies externalized configuration, it is also intentionally strict. One common startup failure that results from this strictness is the exception: The elements were left unbound.
This error indicates that Spring Boot detected configuration properties that could not be bound to any field in a target configuration class. In this tutorial, we’ll explore why this exception occurs, how to fix it, and how to validate configuration binding using JUnit tests.
2. What Does the Elements Were Left Unbound Actually Mean?
When Spring Boot starts, it scans all property sources, including application.yml, application.properties, and profile-specific configuration files. It then attempts to bind these properties to Java classes annotated with @ConfigurationProperties.
If Spring encounters one or more properties that do not match any field in the corresponding configuration class, it fails fast and throws the unbound elements exception.
This behavior ensures configuration correctness and prevents silent misconfigurations.
A common error message looks like this:
Binding to target [Bindable@...] failed:
Property: example.service.timeout
Reason: The elements [example.service.timeout] were left unbound
The message clearly points to the property that could not be bound, making it the primary starting point for debugging.
3. Mismatch Between Properties and Fields
The most common cause of this exception is a mismatch between property names and Java field names.
We define a property in application.yml as follows:
example:
service:
timeout: 5000
Here, Spring Boot expects to bind example.service.timeout to a field named timeout inside a configuration properties class with the prefix example.service.
Now consider the following configuration class:
@Component
@ConfigurationProperties(prefix = "example.service")
public class ServiceProperties {
private int timeOut;
public int getTimeOut() {
return timeOut;
}
public void setTimeOut(int timeOut) {
this.timeOut = timeOut;
}
}
At first glance, this looks correct, but timeout from the configuration does not match timeOut in the class definition. Because of this mismatch, Spring cannot bind the value and throws the unbound elements exception during startup.
To resolve the issue, we align the field name with Spring’s expected binding format:
private int timeout;
Once the field name matches the property key, Spring Boot successfully binds the value during context initialization. This small correction ensures that configuration binding works as intended.
To ensure that property binding behaves correctly, we can write a JUnit test that loads the Spring context with inline properties:
@SpringBootTest(
properties = "example.service.timeout=5000"
)
class ServicePropertiesTest {
@Autowired
private ServiceProperties serviceProperties;
@Test
void shouldBindTimeoutPropertyCorrectly() {
assertThat(serviceProperties.getTimeout()).isEqualTo(5000);
}
}
This test verifies that the property is correctly bound to the timeout field. If we reintroduce the incorrect field name (timeOut), the application context fails to start, and the test immediately exposes the configuration problem.
By adding such tests, we make configuration binding explicit and prevent subtle mismatches from reaching production.
4. Missing Configuration Properties Registration
Another common issue occurs when a @ConfigurationProperties class is not registered as a Spring bean. Let’s have a look at the configuration class without registration:
@ConfigurationProperties(prefix = "example.service")
public class ServiceProperties {
private int timeout;
public int getTimeout() {
return timeout;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
}
In this case, Spring detects the configuration property but does not find a target bean to bind it to. The valid registration happens using @Component:
@Component
@ConfigurationProperties(prefix = "example.service")
public class ServiceProperties {
private int timeout;
}
Another valid registration option is to enable it explicitly using @EnableConfigurationProperties:
@EnableConfigurationProperties(ServiceProperties.class)
@SpringBootApplication
public class MainApplication {
}
5. Conclusion
In this article, we saw that the elements were left unbound exception is a deliberate design choice in Spring Boot. It enforces strict configuration correctness and prevents subtle runtime bugs. By understanding common causes and validating configuration binding through JUnit tests, we can turn this startup exception into a reliable safety mechanism. With these practices in place, configuration issues become predictable, testable, and easy to fix, exactly the way Spring Boot intends.
The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
















