Skip to content

Commit

Permalink
GH-324: Annotate @CircuitBreaker with @AliasFor
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
hpoettker authored Nov 18, 2022
1 parent 0d71058 commit 61960f3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@
public @interface CircuitBreaker {

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

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

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

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

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

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

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

/**
Expand All @@ -107,13 +112,15 @@
* at runtime.
* @since 1.2.3
*/
@AliasFor(annotation = Retryable.class)
String maxAttemptsExpression() default "";

/**
* A unique label for the circuit for reporting and state management. Defaults to the
* method signature where the annotation is declared.
* @return the label for the circuit
*/
@AliasFor(annotation = Retryable.class)
String label() default "";

/**
Expand All @@ -137,7 +144,7 @@
/**
* When {@link #maxAttempts()} failures are reached within this timeout, the circuit
* is opened automatically, preventing access to the downstream component.
* @return the timeout before an closed circuit is opened in milliseconds, defaults to
* @return the timeout before a closed circuit is opened in milliseconds, defaults to
* 5000
*/
long openTimeout() default 5000;
Expand All @@ -147,7 +154,7 @@
* is opened automatically, preventing access to the downstream component. Overrides
* {@link #openTimeout()}. Use {@code #{...}} for one-time evaluation during
* initialization, omit the delimiters for evaluation at runtime.
* @return the timeout before an closed circuit is opened in milliseconds, no default.
* @return the timeout before a closed circuit is opened in milliseconds, no default.
* @since 1.2.3
*/
String openTimeoutExpression() default "";
Expand All @@ -171,6 +178,7 @@
* @return the expression.
* @since 1.2.3
*/
@AliasFor(annotation = Retryable.class)
String exceptionExpression() default "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
String interceptor() default "";

/**
* Exception types that are retryable. Synonym for include(). Defaults to empty (and
* if excludes is also empty all exceptions are retried).
* Exception types that are retryable. Defaults to empty (and if excludes is also
* empty all exceptions are retried).
* @return exception types to retry
* @deprecated in favor of {@link #retryFor()}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static class TestService {

private RetryContext context;

@CircuitBreaker(include = { RuntimeException.class }, openTimeout = 10000, resetTimeout = 15000)
@CircuitBreaker(retryFor = { RuntimeException.class }, openTimeout = 10000, resetTimeout = 15000)
String service(String payload) {
this.context = RetrySynchronizationManager.getContext();
System.out.println("real service called");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected static class ServiceImpl implements Service {
RetryContext context;

@Override
@CircuitBreaker(RuntimeException.class)
@CircuitBreaker(retryFor = RuntimeException.class)
public void service() {
this.context = RetrySynchronizationManager.getContext();
if (this.count++ < 5) {
Expand Down

0 comments on commit 61960f3

Please sign in to comment.