I need to define Duration value (spring.redis.timeout) by application.properties.
I was trying to use one point defined in Spri
Any property which is of type duration can be injected via .properties
or .yml
files.
All you need to do is use a proper formatting.
If you want to inject a duration of 5 seconds it should be defined as PT5S
or pt5s
or PT5s
Other examples
PT1.5S = 1.5 Seconds
PT60S = 60 Seconds
PT3M = 3 Minutes
PT2H = 2 Hours
P3DT5H40M30S = 3Days, 5Hours, 40 Minutes and 30 Seconds
You can also use +ve and -ve signs to denote positive vs negative period of time.
PT-3H30M
= -3 hours, +30 minutes, basically -2.5Hours-PT3H30M
= -3 hours, -30 minutes, basically -3.5Hours-PT-3H+30M
= +3 Hours, -30 Minutes, basically +2.5Hours
Upvote, if it works for you or you like the explanation. Thanks,