You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to this documentation, I should be able to use @DurationUnit to change the default unit when converting a duration. However, the example above keeps using MILLISECONDS as the duration unit.
Happening in the latest Spring version
When not specifying a unit in application.yml:
myconfig:
myDuration: 70
And specifying DurationUnit to SECONDS in config properties class
This has been addressed in 2.4 where @DurationUnit can now be used on constructor parameters. I think we still need to do something in a maintenance branch, though. The problem isn't specific to Kotlin as the following Java does not work either:
@DurationUnit(ChronoUnit.SECONDS)
private final Duration duration;
public MyProperties(Duration duration) {
this.duration = duration;
}
We can't be sure that the duration constructor parameter will be stored in the duration field so there's no way of reliably discovering the duration unit. I suspect the best that we can do is to update the documentation to make it clear that @DurationUnit is only supported with JavaBean-based property binding.
wilkinsona
changed the title
@DurationUnit does not work with constructor binding
Document that constructor binding does not support @DurationUnit and @DataSizeUnit
Jul 30, 2020
According to this documentation, I should be able to use
@DurationUnit
to change the default unit when converting a duration. However, the example above keeps usingMILLISECONDS
as the duration unit.Happening in the
latest
Spring versionapplication.yml
:DurationUnit
toSECONDS
in config properties classMILLISECONDS
unitmyProperties.myDuration.toString() // -> "PT0.07S"
The text was updated successfully, but these errors were encountered: