Skip to content

Retryable with not simple expressions #488

Closed
@artembilan

Description

@artembilan

Discussed in #487

Originally posted by ahoehma March 26, 2025
I'm doing this:

  @Transactional(transactionManager = "historyTransactionManager")
  @Retryable(
    retryFor = {
        org.springframework.dao.PessimisticLockingFailureException.class,
        org.springframework.dao.CannotAcquireLockException.class,
        org.springframework.dao.RecoverableDataAccessException.class,
        org.springframework.dao.DataAccessResourceFailureException.class,
        org.springframework.dao.InvalidDataAccessResourceUsageException.class,
        org.hibernate.exception.LockAcquisitionException.class
    },
    exceptionExpression = "#{@'historyJdbcRetryProperties'.save.enabled}",  // <<<<<<<<<<<<<<<<<<<<<<<<<<
    maxAttemptsExpression = "#{@'historyJdbcRetryProperties'.save.maxAttempts}", // <<<<<<<<<<<<<<<<<<<<<
    backoff = @Backoff(
      delayExpression = "#{@'historyJdbcRetryProperties'.save.backoffDelay}",// <<<<<<<<<<<<<<<<<<<<<<<<<<
      multiplierExpression = "#{@'historyJdbcRetryProperties'.save.backoffMultiplier}"))// <<<<<<<<<<<<<<<<<<<<
  @Timed(HistoryMetrics.TIMER_HISTORY_SAVE)
  @Override
  public ConfigurationHistory save(
      final String configurationId,
      final Configuration configuration,
      final ConfigurationActions configurationActions,
      final List<OrderNumber> orderNumbers,
      final @Nullable VariantTableNames variantTableNames) {
    log.trace("Save history for configuration-id '{}' with configuration '{}', actions '{}', orderNumbers '{}', variantTables '{}'",
        configurationId, configuration, configurationActions, orderNumbers, variantTableNames);
    checkNotNull(configurationId, "Missing configuration-id");
    checkNotNull(configuration, "Missing configuration");
    checkNotNull(configurationActions, "Missing actions");
    checkNotNull(orderNumbers, "Missing order numbers");
    return logTraceDumpSave(internalSave(configurationId, configuration, configurationActions, orderNumbers, variantTableNames));
  }

exceptionExpression = "#{@'historyJdbcRetryProperties'.save.enabled}"

Is my way to enable to disable particular retries. Please imagine I have not only the "save" method ... I have several other methods ... but the @retryable annotation looks almost identical ... only the "action-name" is different. So far so good :) It seems to work and I can enable or disable retry for specific actions.

maxAttemptsExpression = "#{@'historyJdbcRetryProperties'.save.maxAttempts}"
delayExpression = "#{@'historyJdbcRetryProperties'.save.backoffDelay}"
multiplierExpression = "#{@'historyJdbcRetryProperties'.save.backoffMultiplier}"

Same here - I want to control the max-attempts, delay and multiplier per "action".

But then I found this warning in my logs (org.springframework.retry.policy.ExpressionRetryPolicy):

#{...} syntax is not required for this run-time expression and is deprecated in favor of a simple expression string

I can't see which of my expressions are causing this warning.

And is my code soon or later broken ... imagine a new spring-retry release which drops support for complex expressions :O

Please share some hints/ideas with me.

Kind regards
Andreas

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions