0

How to use property from a property file in the @Backoff annotation for customize delay time? This attribute takes only a constant as a value. I try to initialize someProperty field with constructor injection, but it not helps and IntellijIDEA shows a message: "Attribute value must be a constant".

This code won't compile:

public class SomeClass {

    private final long someProperty;

    public SomeClass (@Value("${someProperty}") Long someProperty) {
        this.someProperty = someProperty;
    }

    @Retryable(value = RuntimeException.class, maxAttempts = 2, 
               backoff = @Backoff(delay = someProperty))
    public SomeObject getSomeObject() {
        return new SomeObject();
    }
}

Can I use delayExpression attribute like this:

@Retryable(value = RuntimeException.class, maxAttempts = 2, 
           backoff = @Backoff(delayExpression = "${someProperty}"))
Rinat
  • 362
  • 3
  • 14
  • You cannot create an annotation that is modified at runtime. Annotation metadata is set at compile time only. – Jamie Mar 25 '21 at 12:55
  • 2
    It seems that the question already has an answer https://stackoverflow.com/questions/43143806/how-to-inject-config-properties-in-spring-boot-to-spring-retry-annotation – Rinat Mar 25 '21 at 13:04

0 Answers0