Can I use a Spring @Value variable from properties in another annotation?

Viewed 2586

I currently have a variable coming from a property file, declared as:

    @Value("${retryLimit}")
    private int retryLimit;

That I would like to use in an annotation instead of the hard-coded constant "3" in this case:

    @Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000))

Is this possible?

I've tried:

    @Retryable(maxAttempts = @Value("${retryLimit}"), backoff = @Backoff(delay = 2000))

However I get the following compile error:

"Incompatible types. Found: 'org.springframework.beans.factory.annotation.Value', required: 'int'"
1 Answers

No need to use @value inside another annotation tag. Just use with out @value. It will work.

@Retryable(maxAttempts = "${retryLimit}", backoff = @Backoff(delay = 2000))
Related