Skip to content

Spring 7: SimpleRetryInterceptor could use RetryListener beans #35526

@ah1508

Description

@ah1508

When a method is annotated by @Retryable, the interceptor does not use RetryListeners beans. The listeners are easy to plug in RetryTemplate but could also be considered by the interceptor

@SpringBootApplication
@EnableResilientMethods
public class EntryPoint {

    @Bean
    RetryListener retryListener(){
        return new RetryListener() {
            @Override
            public void beforeRetry(RetryPolicy retryPolicy, org.springframework.core.retry.Retryable<?> retryable) {
                System.out.println("...");
            }

            @Override
            public void onRetrySuccess(RetryPolicy retryPolicy, org.springframework.core.retry.Retryable<?> retryable, @Nullable Object result) {
                System.out.println("...");
            }
        };
    }

    public static void main(String[] args) {
        var ctx = SpringApplication.run(EntryPoint.class, args);
        ctx.getBean(A.class).foo();
    }
}

@Component
class A {
    private boolean b = true;

    @Retryable(includes = RuntimeException.class)
    public void foo(){
        if(b) {
            b = false;
            throw new RuntimeException();
        }
        System.out.println("ok");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions