Skip to content

Commit 61960f3

Browse files
authored
GH-324: Annotate @CircuitBreaker with @AliasFor
Fixes #324 Using the annotation `@CircuitBreaker` with Spring Framework 6 leads to the following warning: ``` WARN org.springframework.core.annotation.AnnotationTypeMapping [main] : Support for convention-based annotation attribute overrides is deprecated and will be removed in Spring Framework 6.1. Please annotate the following attributes in @org.springframework.retry.annotation.CircuitBreaker with appropriate @AliasFor declarations: [include, maxAttempts, noRetryFor, maxAttemptsExpression, notRecoverable, exclude, exceptionExpression, label, retryFor] ``` * Provide a respective fix for `@CircuitBreaker` annotation. * Deprecated attributes which are deprecated already in the `@Retriable`
1 parent 0d71058 commit 61960f3

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/main/java/org/springframework/retry/annotation/CircuitBreaker.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@
4040
public @interface CircuitBreaker {
4141

4242
/**
43-
* Exception types that are retryable. Synonym for includes(). Defaults to empty (and
44-
* if excludes is also empty all exceptions are retried).
43+
* Exception types that are retryable. Defaults to empty (and if excludes is also
44+
* empty all exceptions are retried).
4545
* @return exception types to retry
46+
* @deprecated in favor of {@link #retryFor()}
4647
*/
48+
@AliasFor(annotation = Retryable.class)
49+
@Deprecated
4750
Class<? extends Throwable>[] value() default {};
4851

4952
/**
@@ -52,7 +55,7 @@
5255
* @return exception types to retry
5356
* @deprecated in favor of {@link #retryFor()}.
5457
*/
55-
@AliasFor("retryFor")
58+
@AliasFor(annotation = Retryable.class)
5659
@Deprecated
5760
Class<? extends Throwable>[] include() default {};
5861

@@ -62,7 +65,7 @@
6265
* @return exception types to retry
6366
* @since 2.0
6467
*/
65-
@AliasFor("include")
68+
@AliasFor(annotation = Retryable.class)
6669
Class<? extends Throwable>[] retryFor() default {};
6770

6871
/**
@@ -73,7 +76,7 @@
7376
* @deprecated in favor of {@link #noRetryFor()}.
7477
*/
7578
@Deprecated
76-
@AliasFor("noRetryFor")
79+
@AliasFor(annotation = Retryable.class)
7780
Class<? extends Throwable>[] exclude() default {};
7881

7982
/**
@@ -83,7 +86,7 @@
8386
* @return exception types not to retry
8487
* @since 2.0
8588
*/
86-
@AliasFor("exclude")
89+
@AliasFor(annotation = Retryable.class)
8790
Class<? extends Throwable>[] noRetryFor() default {};
8891

8992
/**
@@ -93,11 +96,13 @@
9396
* @return exception types not to retry
9497
* @since 2.0
9598
*/
99+
@AliasFor(annotation = Retryable.class)
96100
Class<? extends Throwable>[] notRecoverable() default {};
97101

98102
/**
99103
* @return the maximum number of attempts (including the first failure), defaults to 3
100104
*/
105+
@AliasFor(annotation = Retryable.class)
101106
int maxAttempts() default 3;
102107

103108
/**
@@ -107,13 +112,15 @@
107112
* at runtime.
108113
* @since 1.2.3
109114
*/
115+
@AliasFor(annotation = Retryable.class)
110116
String maxAttemptsExpression() default "";
111117

112118
/**
113119
* A unique label for the circuit for reporting and state management. Defaults to the
114120
* method signature where the annotation is declared.
115121
* @return the label for the circuit
116122
*/
123+
@AliasFor(annotation = Retryable.class)
117124
String label() default "";
118125

119126
/**
@@ -137,7 +144,7 @@
137144
/**
138145
* When {@link #maxAttempts()} failures are reached within this timeout, the circuit
139146
* is opened automatically, preventing access to the downstream component.
140-
* @return the timeout before an closed circuit is opened in milliseconds, defaults to
147+
* @return the timeout before a closed circuit is opened in milliseconds, defaults to
141148
* 5000
142149
*/
143150
long openTimeout() default 5000;
@@ -147,7 +154,7 @@
147154
* is opened automatically, preventing access to the downstream component. Overrides
148155
* {@link #openTimeout()}. Use {@code #{...}} for one-time evaluation during
149156
* initialization, omit the delimiters for evaluation at runtime.
150-
* @return the timeout before an closed circuit is opened in milliseconds, no default.
157+
* @return the timeout before a closed circuit is opened in milliseconds, no default.
151158
* @since 1.2.3
152159
*/
153160
String openTimeoutExpression() default "";
@@ -171,6 +178,7 @@
171178
* @return the expression.
172179
* @since 1.2.3
173180
*/
181+
@AliasFor(annotation = Retryable.class)
174182
String exceptionExpression() default "";
175183

176184
}

src/main/java/org/springframework/retry/annotation/Retryable.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
String interceptor() default "";
5555

5656
/**
57-
* Exception types that are retryable. Synonym for include(). Defaults to empty (and
58-
* if excludes is also empty all exceptions are retried).
57+
* Exception types that are retryable. Defaults to empty (and if excludes is also
58+
* empty all exceptions are retried).
5959
* @return exception types to retry
6060
* @deprecated in favor of {@link #retryFor()}
6161
*/

src/test/java/org/springframework/retry/annotation/CircuitBreakerResetTimeoutTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static class TestService {
8787

8888
private RetryContext context;
8989

90-
@CircuitBreaker(include = { RuntimeException.class }, openTimeout = 10000, resetTimeout = 15000)
90+
@CircuitBreaker(retryFor = { RuntimeException.class }, openTimeout = 10000, resetTimeout = 15000)
9191
String service(String payload) {
9292
this.context = RetrySynchronizationManager.getContext();
9393
System.out.println("real service called");

src/test/java/org/springframework/retry/annotation/CircuitBreakerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ protected static class ServiceImpl implements Service {
166166
RetryContext context;
167167

168168
@Override
169-
@CircuitBreaker(RuntimeException.class)
169+
@CircuitBreaker(retryFor = RuntimeException.class)
170170
public void service() {
171171
this.context = RetrySynchronizationManager.getContext();
172172
if (this.count++ < 5) {

0 commit comments

Comments
 (0)