diff --git a/src/main/java/org/springframework/retry/annotation/CircuitBreaker.java b/src/main/java/org/springframework/retry/annotation/CircuitBreaker.java index a45f10fa..31fc5f1f 100644 --- a/src/main/java/org/springframework/retry/annotation/CircuitBreaker.java +++ b/src/main/java/org/springframework/retry/annotation/CircuitBreaker.java @@ -190,4 +190,13 @@ */ boolean throwLastExceptionOnExhausted() default false; + /** + * Name of method in this class to use for recover. Method had to be marked with + * {@link Recover} annotation. + * @return the name of recover method + * @since 2.0.9 + */ + @AliasFor(annotation = Retryable.class) + String recover() default ""; + } diff --git a/src/test/java/org/springframework/retry/stats/CircuitBreakerInterceptorStatisticsTests.java b/src/test/java/org/springframework/retry/stats/CircuitBreakerInterceptorStatisticsTests.java index 7e60c9ff..b56dd127 100644 --- a/src/test/java/org/springframework/retry/stats/CircuitBreakerInterceptorStatisticsTests.java +++ b/src/test/java/org/springframework/retry/stats/CircuitBreakerInterceptorStatisticsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2023 the original author or authors. + * Copyright 2006-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ /** * @author Dave Syer + * @author Artem Bilan * */ public class CircuitBreakerInterceptorStatisticsTests { @@ -106,7 +107,7 @@ protected static class Service { private RetryContext status; - @CircuitBreaker(label = "test", maxAttempts = 1) + @CircuitBreaker(label = "test", maxAttempts = 1, recover = "recover") public Object service(String input) throws Exception { this.status = RetrySynchronizationManager.getContext(); Integer attempts = (Integer) status.getAttribute("attempts"); @@ -122,11 +123,16 @@ public Object service(String input) throws Exception { } @Recover - public Object recover() { + public Object recover(String input) { this.status.setAttribute(RECOVERED, true); return RECOVERED; } + @Recover + public Object anotherRecover(Object input) { + return null; + } + public boolean isOpen() { return this.status != null && this.status.getAttribute("open") == Boolean.TRUE; }