4

Below parameter, trying to make configurable

@Async("threadPoolTaskExecutor")
@Retryable(value = MessagingException.class, maxAttempts = 2, backoff = @Backoff(delay = 5000))

I did the following changes in application.properties file

my.app.maxAttempts = 2
my.app.backOffDelay = 5000

and

@Retryable(value = MessagingException.class, maxAttempts = "${my.app.maxAttempts}", backoff = @Backoff(delay = "${my.app.my.app.backOffDelay}"))

But getting following error. incompatible type. foundjava.lang.String. required 'int'

In build.gradle file I have

dependencies {
    compile ("org.springframework.boot:spring-boot-starter-web")
    compile ("org.springframework.boot:spring-boot-starter-mail:2.1.2.RELEASE")
    compile ("org.springframework.boot:spring-boot-starter-security:2.1.2.RELEASE")
    compile ("org.springframework.boot:spring-boot-starter-aop")
    compile ("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-jdbc:2.1.0.RELEASE")
    compile ("org.springframework.retry:spring-retry:1.2.4.RELEASE")
    compile ("io.springfox:springfox-swagger2:2.9.2")
    compile ("io.springfox:springfox-swagger-ui:2.9.2")
    compile ("io.springfox:springfox-bean-validators:2.9.2")
    compile ("javax.validation:validation-api:2.0.0.Final")
    compile ("org.hibernate.validator:hibernate-validator")
    compile ("org.hibernate.validator:hibernate-validator-annotation-processor")
//  compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.9.8'
    compile ("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.8")
    compile("org.postgresql:postgresql")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    testImplementation('org.springframework.boot:spring-boot-starter-test')
    testImplementation('org.springframework.batch:spring-batch-test')
    testCompile group: 'org.springframework.security', name: 'spring-security-test', version: '4.0.0.RELEASE'
}

1 Answer 1

26

Use the expression to

@Retryable(value = MessagingException.class, maxAttemptsExpression = "${my.app.maxAttempts}", backoff = @Backoff(delayExpression = "${my.app.my.app.backOffDelay}"))

This should work

4
  • 1
    Yes i did this recently. Also , you can use that Spring EL to maybe call a method and load from a different place if you want to. Commented Jun 21, 2019 at 7:18
  • How to test Retryable is working with configured max attempt?
    – Praveen D
    Commented Jun 23, 2019 at 18:13
  • @PraveenD use RetryListenerSupport to log the nos of attempt
    – sitakant
    Commented Jun 24, 2019 at 5:25
  • @PraveenD put this in and put logs. if (++testAttempt < 5) { throw new Exception(); } testAttempt = 0; Commented Oct 20, 2023 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.