I am using spring-retry-1.2.0.RELEASE.jar and using below Retryable annotation in service methods
@Retryable(value = {CustomException.class},
maxAttemptsExpression = "#{'${max.retry.attempts}'}",
backoff = @Backoff(delayExpression = "#{'${retry.delay}'}"))
In the logs seeing below exception due to maxAttemptsExpression value and same error when we used Interger.ParseInt/Interger.ValueOf also.
org.springframework.expression.spel.SpelEvaluationException: EL1001E:(pos 0): Type conversion problem, cannot convert from java.lang.String to java.lang.Integer
I see this exception only on few @Retryable service methods and remaining @Retryable methods are working fine. I have no idea what's happening here and we see the value also before hitting to annotation
Remove the #{' and '} (including the single quotes).
@Retryable(maxAttemptsExpression = "${max.retry.attempts}")
The #{...} is not needed here.
You should also upgrade to 1.2.1.RELEASE.
EDIT
Something else must be going on; both forms work fine for me...
@SpringBootApplication
@EnableRetry
public class So48309090Application {
public static void main(String[] args) {
SpringApplication.run(So48309090Application.class, args);
}
@Bean
public ApplicationRunner runner(Foo foo) {
return args -> {
try {
foo.foo();
}
catch (RuntimeException e) {
}
try {
foo.bar();
}
catch (RuntimeException e) {
}
};
}
@Component
public static class Foo {
@Retryable(maxAttemptsExpression = "${max.attempts}")
public void foo() {
System.out.println("foo");
throw new RuntimeException("c");
}
@Retryable(maxAttemptsExpression = "#{'${max.attempts}'}")
public void bar() {
System.out.println("bar");
throw new RuntimeException("c");
}
}
}
application.properties
max.attempts=5
and
foo
foo
foo
foo
foo
bar
bar
bar
bar
bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With