Skip to content

Document that constructor binding does not support @DurationUnit and @DataSizeUnit #22565

@jordigarcl

Description

@jordigarcl

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

  1. When not specifying a unit in application.yml:
myconfig:
  myDuration: 70
  1. And specifying DurationUnit to SECONDS in config properties class
@ConstructorBinding
@ConfigurationProperties("myconfig")
class MyProperties(
  @DurationUnit(ChronoUnit.SECONDS)
  val myDuration: Duration,
)
  1. Then duration is converted using default MILLISECONDS unit
myProperties.myDuration.toString() // -> "PT0.07S"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions