Quick revision
The short answer
When Spring Boot binds a plain number to a Duration field, it treats the number as milliseconds by default, so timeout: 5000 becomes 5 seconds. The service that gets 5000 seconds almost certainly has @DurationUnit(ChronoUnit.SECONDS) on its field, which changes the unit used for plain numbers. The lasting fix is to write durations with their unit, such as 5s or 500ms, so the value means the same thing in every class.
What to remember
In this answer, we saw that Spring Boot reads a plain number bound to a Duration as milliseconds, so timeout: 5000 means 5 seconds, while @DurationUnit(ChronoUnit.SECONDS) on a field makes the same number mean 5000 seconds. The service with the long timeout has that annotation. The lasting fix is to write durations with units such as 5s or 500ms, check the bound value with the configprops endpoint or a startup log, and remember that DataSize and Period follow the same pattern.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
When Spring Boot binds a plain number to a Duration field, it treats the number as milliseconds by default, so timeout: 5000 becomes 5 seconds. The service that gets 5000 seconds almost certainly has @DurationUnit(ChronoUnit.SECONDS) on its field, which changes the unit used for plain numbers. The lasting fix is to write durations with their unit, such as 5s or 500ms, so the value means the same thing in every class.
Background to this question
Timeouts are among the most sensitive settings in any service. A timeout of 5000 seconds instead of 5 means a stuck downstream call holds a thread for over an hour, and the problem only shows up when something else fails. This question looks like trivia, but it tests whether we understand how Spring Boot converts configuration strings into types, and how one annotation can change the meaning of an identical line in two services. In this answer, we will recap how Duration binding works, reproduce the two behaviours, find the cause, look at other ways the same symptom can appear, and fix it so it cannot come back.
1A Quick Recap of Duration Binding
A java.time.Duration is a length of time, such as 5 seconds or 300 milliseconds. Configuration files only contain text, so Spring Boot must convert the text into a Duration when it binds a @ConfigurationProperties field. It accepts three forms. A simple form with a unit, such as 5s, 500ms or 2m. The ISO-8601 form used by Duration.parse, such as PT5S. And a plain number such as 5000, with no unit at all.
For the plain number, Spring Boot has to decide on a unit, and the default is milliseconds. That default is the heart of this question.
2Reproducing the Two Behaviours
Here are the two services. Both have the line timeout: 5000 in their YAML under their own prefix, and both bind it to a Duration. The only difference is one annotation on the field.
- Read the text value"5000"
- Does it have a unit or ISO form?5s, 500ms, PT5SYesUse the unit written: same everywhereNoContinue: a plain number
- Is @DurationUnit on the field?for example
ChronoUnit.SECONDSYesUse that unit: 5000 secondsNoUse milliseconds: 5 seconds
3 steps in order. Play them, or step through them one at a time.
Notice that the YAML is identical and both services are correct according to their own code. @DurationUnit tells Spring Boot which unit to use when the value is a plain number. Someone added it to service B, probably so that operators could write timeout: 30 to mean 30 seconds, and the same habit of writing 5000 for five seconds then produced 5000 seconds.
3Finding the Cause in a Running Service
We can confirm the bound value without reading the code. The Actuator configprops endpoint shows the bound properties of each @ConfigurationProperties bean, so we can compare the Duration each service actually holds. With values masked we may need an authorised user, but a quick log line at startup gives the same answer.
Once we see PT1H23M20S, a search for @DurationUnit in that service finds the annotation. It is also worth checking older code that does not use Duration at all: a long timeoutMs field read with @Value and later passed to Duration.ofSeconds produces the same symptom, because the unit is decided in Java code instead of by the binder.
4Fix: Write the Unit in the Value
We could remove the annotation from service B, but that would silently change every other value that relies on it, such as timeout: 30 that now means 30 seconds. The safer fix is to write units in the configuration so that the annotation no longer matters.
With the unit written, both services get exactly 5 seconds, whatever @DurationUnit says. So the rule for the whole team is that durations in configuration always carry a unit. We can enforce it with a simple CI check over YAML files for keys ending in timeout, delay or interval with a plain number, or with validation in the properties class, such as rejecting a timeout above a sensible maximum with a custom check, so that 5000 seconds fails at startup.
5Related Conversions With the Same Trap
The same design applies to other types. DataSize, used for sizes such as 10MB, treats a plain number as bytes unless @DataSizeUnit says otherwise, and Period, used for dates, treats a plain number as days unless @PeriodUnit says otherwise. In each case the annotation changes the meaning of plain numbers only, and the cure is the same: write the unit, such as 10MB or 2d.
| Type | Default unit for plain numbers | Annotation to change it | Safer value |
|---|---|---|---|
| Duration | milliseconds | @DurationUnit | 5s, 500ms |
DataSize | bytes | @DataSizeUnit | 10MB, 512KB |
| Period | days | @PeriodUnit | 2d, 1w, 3m |
6Follow-up questions
Does @Value convert durations the same way?
@Value converts through Spring Boot's conversion service too, so 5s works, but @DurationUnit only applies to @ConfigurationProperties binding. For plain numbers read with @Value, check your version's behaviour, or better, always write a unit.
Why is milliseconds the default?
Because many older timeout properties in Java libraries were numbers of milliseconds, so treating a bare number as milliseconds keeps such values working when a field is changed from long to Duration.
How would you add a maximum to a Duration field?
Bean Validation has no built-in constraint for Duration, so a small custom constraint or a check in the record's compact constructor works, for example throwing an IllegalArgumentException if timeout is longer than 60 seconds, which Spring Boot reports as a binding failure at startup.
7Conclusion
In this answer, we saw that Spring Boot reads a plain number bound to a Duration as milliseconds, so timeout: 5000 means 5 seconds, while @DurationUnit(ChronoUnit.SECONDS) on a field makes the same number mean 5000 seconds. The service with the long timeout has that annotation. The lasting fix is to write durations with units such as 5s or 500ms, check the bound value with the configprops endpoint or a startup log, and remember that DataSize and Period follow the same pattern.
Open with
When Spring Boot binds a plain number to a Duration in @ConfigurationProperties, it uses milliseconds by default, so timeout: 5000 becomes five seconds. Spring Boot lets a field change that default with @DurationUnit, for example @DurationUnit(ChronoUnit.SECONDS), and then the same 5000 means 5000 seconds, which is about an hour and twenty-three minutes.
Then, if they want more
So the service with the huge timeout almost certainly has @DurationUnit with seconds on its field, probably added so people could write 30 for thirty seconds. To confirm it, I would look at the bound value through the configprops endpoint, or log the Duration at startup, where I would see PT1H23M20S, and then search for @DurationUnit.
I would also check for older code that reads a long with @Value and calls Duration.ofSeconds, which gives the same symptom. For the fix, I would not just remove the annotation, because other values may now rely on it. Instead I would write units in the configuration, like 5s or 500ms, or the ISO form PT5S.
With a unit, the annotation no longer matters and every service reads the same value. Then I would make that a team rule with a CI check, and maybe add a startup check for a sensible maximum. DataSize and Period have the same trap, with bytes and days as defaults.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A property timeout: 5000 bound to a Duration field in @ConfigurationProperties results...": https://scrivio-interview-library.netlify.app/spring-boot/externalized-configuration/8fee3988e4/