Annotation Interface Retryable


@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented @Reflective public @interface Retryable
A common annotation specifying retry characteristics for an individual method, or for all proxy-invoked methods in a given class hierarchy if annotated at the type level.

Aligned with RetryTemplate as well as Reactor's retry support, either re-invoking an imperative target method or decorating a reactive result accordingly.

Inspired by the Spring Retry project but redesigned as a minimal core retry feature in the Spring Framework.

Since:
7.0
Author:
Juergen Hoeller
See Also:
  • Element Details

    • value

      @AliasFor("includes") Class<? extends Throwable>[] value
      Convenient default attribute for includes(), typically used with a single exception type to retry for.
      Default:
      {}
    • includes

      @AliasFor("value") Class<? extends Throwable>[] includes
      Applicable exception types to attempt a retry for. This attribute allows for the convenient specification of assignable exception types.

      The default is empty, leading to a retry attempt for any exception.

      See Also:
      Default:
      {}
    • excludes

      Class<? extends Throwable>[] excludes
      Non-applicable exception types to avoid a retry for. This attribute allows for the convenient specification of assignable exception types.

      The default is empty, leading to a retry attempt for any exception.

      See Also:
      Default:
      {}
    • predicate

      Class<? extends MethodRetryPredicate> predicate
      A predicate for filtering applicable exceptions for which an invocation can be retried.

      The default is a retry attempt for any exception.

      A specified MethodRetryPredicate implementation will be instantiated per method. It can use dependency injection at the constructor level or through autowiring annotations, in case it needs access to other beans or facilities.

      See Also:
      Default:
      org.springframework.resilience.retry.MethodRetryPredicate.class
    • maxAttempts

      long maxAttempts
      The maximum number of retry attempts, in addition to the initial invocation.

      The default is 3.

      Default:
      3L
    • maxAttemptsString

      String maxAttemptsString
      The maximum number of retry attempts, as a configurable String. A non-empty value specified here overrides the maxAttempts() attribute.

      This supports Spring-style "${...}" placeholders as well as SpEL expressions.

      See Also:
      Default:
      ""
    • delay

      long delay
      The base delay after the initial invocation. If a multiplier is specified, this serves as the initial delay to multiply from.

      The time unit is milliseconds by default but can be overridden via timeUnit().

      Must be greater than or equal to zero. The default is 1000.

      See Also:
      Default:
      1000L
    • delayString

      String delayString
      The base delay after the initial invocation, as a duration String. A non-empty value specified here overrides the delay() attribute.

      The duration String can be in several formats:

      • a plain integer — which is interpreted to represent a duration in milliseconds by default unless overridden via timeUnit() (prefer using delay() in that case)
      • any of the known DurationFormat.Style: the ISO8601 style or the SIMPLE style — using the timeUnit() as fallback if the string doesn't contain an explicit unit
      • one of the above, with Spring-style "${...}" placeholders as well as SpEL expressions
      Returns:
      the initial delay as a String value — for example a placeholder, or a java.time.Duration compliant value or a simple format compliant value
      See Also:
      Default:
      ""
    • jitter

      long jitter
      A jitter value for the base retry attempt, randomly subtracted or added to the calculated delay, resulting in a value between delay - jitter and delay + jitter but never below the base delay() or above maxDelay(). If a multiplier is specified, it is applied to the jitter value as well.

      The time unit is milliseconds by default but can be overridden via timeUnit().

      The default is 0 (no jitter).

      See Also:
      Default:
      0L
    • jitterString

      String jitterString
      A jitter value for the base retry attempt, as a duration String. A non-empty value specified here overrides the jitter() attribute.

      The duration String can be in several formats:

      • a plain integer — which is interpreted to represent a duration in milliseconds by default unless overridden via timeUnit() (prefer using jitter() in that case)
      • any of the known DurationFormat.Style: the ISO8601 style or the SIMPLE style — using the timeUnit() as fallback if the string doesn't contain an explicit unit
      • one of the above, with Spring-style "${...}" placeholders as well as SpEL expressions
      Returns:
      the initial delay as a String value — for example a placeholder, or a java.time.Duration compliant value or a simple format compliant value
      See Also:
      Default:
      ""
    • multiplier

      double multiplier
      A multiplier for a delay for the next retry attempt, applied to the previous delay (starting with delay()) as well as to the applicable jitter() for each attempt.

      The default is 1.0, effectively resulting in a fixed delay.

      See Also:
      Default:
      1.0
    • multiplierString

      String multiplierString
      A multiplier for a delay for the next retry attempt, as a configurable String. A non-empty value specified here overrides the multiplier() attribute.

      This supports Spring-style "${...}" placeholders as well as SpEL expressions.

      See Also:
      Default:
      ""
    • maxDelay

      long maxDelay
      The maximum delay for any retry attempt, limiting how far jitter() and multiplier() can increase the delay.

      The time unit is milliseconds by default but can be overridden via timeUnit().

      The default is unlimited.

      See Also:
      Default:
      9223372036854775807L
    • maxDelayString

      String maxDelayString
      The maximum delay for any retry attempt, as a duration String. A non-empty value specified here overrides the maxDelay() attribute.

      The duration String can be in several formats:

      • a plain integer — which is interpreted to represent a duration in milliseconds by default unless overridden via timeUnit() (prefer using maxDelay() in that case)
      • any of the known DurationFormat.Style: the ISO8601 style or the SIMPLE style — using the timeUnit() as fallback if the string doesn't contain an explicit unit
      • one of the above, with Spring-style "${...}" placeholders as well as SpEL expressions
      Returns:
      the initial delay as a String value — for example a placeholder, or a java.time.Duration compliant value or a simple format compliant value
      See Also:
      Default:
      ""
    • timeUnit

      TimeUnit timeUnit
      The TimeUnit to use for delay(), delayString(), jitter(), jitterString(), maxDelay(), and maxDelayString().

      The default is TimeUnit.MILLISECONDS.

      This attribute is ignored for Duration values supplied via delayString(), jitterString(), or maxDelayString().

      Returns:
      the TimeUnit to use
      Default:
      MILLISECONDS