简体   繁体   中英

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

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'"

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM