Spring / Spring Retry Interview Questions
What is the RetryOperationsInterceptor and how is it used?
RetryOperationsInterceptor is an AOP method interceptor provided by Spring Retry that allows you to apply retry behavior to beans programmatically without using @Retryable annotations. It bridges Spring AOP (MethodInterceptor) with Spring Retry (RetryOperations/RetryTemplate).
This is useful when you want to apply retry to third-party beans that you cannot annotate, or when you need more dynamic retry configuration than annotations allow.
Programmatic setup with a custom advisor:
@Bean public RetryOperationsInterceptor retryInterceptor() { return RetryInterceptorBuilder.stateless() .maxAttempts(4) .backOffOptions(1000, 2.0, 10000) .recoverer(new ItemRecoverer()) .build(); } @Bean public BeanFactoryPostProcessor retryAdvisor(RetryOperationsInterceptor interceptor) { // Apply interceptor to specific beans via Advisor }
Spring Retry also provides StatefulRetryOperationsInterceptor for stateful retry scenarios (common in Spring Batch). Both interceptors can be built using the RetryInterceptorBuilder factory:
RetryInterceptorBuilder.stateless()— creates a stateless interceptorRetryInterceptorBuilder.stateful()— creates a stateful interceptor with key generator support
More Related questions...