Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Spring Boot style flexible Duration value parsing [SPR-17481] #22013

Closed
spring-projects-issues opened this issue Nov 8, 2018 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

manderson23 opened SPR-17481 and commented

Spring Boot supports specifying duration values in property files using values such as 15ms, 10s etc. (See spring-projects/spring-boot#11078).

However, this means that there are inconsistencies when trying to use the values of these properties with Spring Framework annotations. An example was provided in spring-projects/spring-boot#15126 where I would like to use a property value in a Scheduled annotation e.g.

@Scheduled(fixedRateString = "${my-prop.rate}")

In this case I have to specify the property value using java.time.Duration syntax instead of the Spring Boot flexible syntax as ScheduledAnnotationBeanPostProcessor is hardcoded to use java.time.Duration parsing.

It would be good if Spring Framework also supported the flexible syntax to allow consistent property values to be used.


Affects: 5.1.2

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.x Backlog milestone Jan 11, 2019
ilyavy added a commit to ilyavy/spring-framework that referenced this issue Feb 4, 2020
dkfellows added a commit to SpiNNakerManchester/JavaSpiNNaker that referenced this issue Aug 31, 2021
This is such a dumb thing. And Spring have just sat on it for nearly 3
years, because why would you have one fundamental value parser when you
could have many?
@simonbasle simonbasle added the status: superseded An issue that has been superseded by another label May 16, 2023
@simonbasle simonbasle self-assigned this May 16, 2023
@simonbasle simonbasle modified the milestones: 6.x Backlog, 6.1.0-M1 May 16, 2023
@simonbasle
Copy link
Contributor

linked to #22474 and superseded by gh-30396

@simonbasle simonbasle closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2023
@jhoeller jhoeller removed this from the 6.1.0-M1 milestone Jun 30, 2023
@psyskeptic

This comment was marked as off-topic.

bclozel pushed a commit that referenced this issue Jul 23, 2024
This commit introduces a notion of different styles for the formatting
of Duration.
The `@DurationFormat` annotation is added to ease selection of a style,
which are represented as DurationFormat.Style enum, as well as a
supported time unit represented as DurationFormat.Unit enum.

DurationFormatter has been retroffited to take such a Style,
optionally, at construction. The default is still the JDK style a.k.a.
ISO-8601.

This introduces the new SIMPLE style which uses a single number + a
short human-readable suffix. For instance "-3ms" or "2h".

This has the same semantics as the DurationStyle in Spring Boot and
is intended as a replacement for that feature, providing access to the
feature to projects that only depend on Spring Framework.

Finally, the `@Scheduled` annotation is improved by adding detection
of the style and parsing for the String versions of initial delay, fixed
delay and fixed rate.

See gh-22013
See gh-22474

Closes gh-30396
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants