diff --git a/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/bulkhead/autoconfigure/AbstractBulkheadConfigurationOnMissingBean.java b/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/bulkhead/autoconfigure/AbstractBulkheadConfigurationOnMissingBean.java index 1c27140f13..31dc5eabfe 100644 --- a/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/bulkhead/autoconfigure/AbstractBulkheadConfigurationOnMissingBean.java +++ b/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/bulkhead/autoconfigure/AbstractBulkheadConfigurationOnMissingBean.java @@ -17,18 +17,14 @@ import io.github.resilience4j.bulkhead.BulkheadRegistry; import io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry; -import io.github.resilience4j.bulkhead.configure.BulkheadAspect; -import io.github.resilience4j.bulkhead.configure.BulkheadAspectExt; -import io.github.resilience4j.bulkhead.configure.BulkheadConfiguration; -import io.github.resilience4j.bulkhead.configure.BulkheadConfigurationProperties; -import io.github.resilience4j.bulkhead.configure.ReactorBulkheadAspectExt; -import io.github.resilience4j.bulkhead.configure.RxJava2BulkheadAspectExt; +import io.github.resilience4j.bulkhead.configure.*; import io.github.resilience4j.bulkhead.configure.threadpool.ThreadPoolBulkheadConfiguration; import io.github.resilience4j.bulkhead.event.BulkheadEvent; import io.github.resilience4j.common.bulkhead.configuration.ThreadPoolBulkheadConfigurationProperties; import io.github.resilience4j.consumer.EventConsumerRegistry; import io.github.resilience4j.fallback.FallbackDecorators; import io.github.resilience4j.fallback.autoconfigure.FallbackConfigurationOnMissingBean; +import io.github.resilience4j.utils.AspectJOnClasspathCondition; import io.github.resilience4j.utils.ReactorOnClasspathCondition; import io.github.resilience4j.utils.RxJava2OnClasspathCondition; import org.springframework.beans.factory.annotation.Autowired; @@ -64,6 +60,7 @@ public BulkheadRegistry bulkheadRegistry(BulkheadConfigurationProperties bulkhea } @Bean + @Conditional(value = {AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean public BulkheadAspect bulkheadAspect(BulkheadConfigurationProperties bulkheadConfigurationProperties, ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry, BulkheadRegistry bulkheadRegistry, @Autowired(required = false) List bulkHeadAspectExtList, @@ -72,14 +69,14 @@ public BulkheadAspect bulkheadAspect(BulkheadConfigurationProperties bulkheadCon } @Bean - @Conditional(value = {RxJava2OnClasspathCondition.class}) + @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean public RxJava2BulkheadAspectExt rxJava2BulkHeadAspectExt() { return bulkheadConfiguration.rxJava2BulkHeadAspectExt(); } @Bean - @Conditional(value = {ReactorOnClasspathCondition.class}) + @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean public ReactorBulkheadAspectExt reactorBulkHeadAspectExt() { return bulkheadConfiguration.reactorBulkHeadAspectExt(); diff --git a/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/AbstractCircuitBreakerConfigurationOnMissingBean.java b/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/AbstractCircuitBreakerConfigurationOnMissingBean.java index 4a4d849254..b2e28855a3 100644 --- a/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/AbstractCircuitBreakerConfigurationOnMissingBean.java +++ b/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/circuitbreaker/autoconfigure/AbstractCircuitBreakerConfigurationOnMissingBean.java @@ -22,6 +22,7 @@ import io.github.resilience4j.consumer.EventConsumerRegistry; import io.github.resilience4j.fallback.FallbackDecorators; import io.github.resilience4j.fallback.autoconfigure.FallbackConfigurationOnMissingBean; +import io.github.resilience4j.utils.AspectJOnClasspathCondition; import io.github.resilience4j.utils.ReactorOnClasspathCondition; import io.github.resilience4j.utils.RxJava2OnClasspathCondition; import org.springframework.beans.factory.annotation.Autowired; @@ -67,6 +68,7 @@ public CircuitBreakerRegistry circuitBreakerRegistry(EventConsumerRegistry circuitBreakerAspectExtList, FallbackDecorators fallbackDecorators) { @@ -74,14 +76,14 @@ public CircuitBreakerAspect circuitBreakerAspect(CircuitBreakerRegistry circuitB } @Bean - @Conditional(value = {RxJava2OnClasspathCondition.class}) + @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean public RxJava2CircuitBreakerAspectExt rxJava2CircuitBreakerAspect() { return circuitBreakerConfiguration.rxJava2CircuitBreakerAspect(); } @Bean - @Conditional(value = {ReactorOnClasspathCondition.class}) + @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean public ReactorCircuitBreakerAspectExt reactorCircuitBreakerAspect() { return circuitBreakerConfiguration.reactorCircuitBreakerAspect(); diff --git a/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/AbstractRateLimiterConfigurationOnMissingBean.java b/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/AbstractRateLimiterConfigurationOnMissingBean.java index b1847acd9f..33ca3061af 100644 --- a/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/AbstractRateLimiterConfigurationOnMissingBean.java +++ b/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/ratelimiter/autoconfigure/AbstractRateLimiterConfigurationOnMissingBean.java @@ -15,8 +15,15 @@ */ package io.github.resilience4j.ratelimiter.autoconfigure; -import java.util.List; - +import io.github.resilience4j.consumer.EventConsumerRegistry; +import io.github.resilience4j.fallback.FallbackDecorators; +import io.github.resilience4j.fallback.autoconfigure.FallbackConfigurationOnMissingBean; +import io.github.resilience4j.ratelimiter.RateLimiterRegistry; +import io.github.resilience4j.ratelimiter.configure.*; +import io.github.resilience4j.ratelimiter.event.RateLimiterEvent; +import io.github.resilience4j.utils.AspectJOnClasspathCondition; +import io.github.resilience4j.utils.ReactorOnClasspathCondition; +import io.github.resilience4j.utils.RxJava2OnClasspathCondition; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; @@ -24,19 +31,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import io.github.resilience4j.consumer.EventConsumerRegistry; -import io.github.resilience4j.ratelimiter.RateLimiterRegistry; -import io.github.resilience4j.ratelimiter.configure.RateLimiterAspect; -import io.github.resilience4j.ratelimiter.configure.RateLimiterAspectExt; -import io.github.resilience4j.ratelimiter.configure.RateLimiterConfiguration; -import io.github.resilience4j.ratelimiter.configure.RateLimiterConfigurationProperties; -import io.github.resilience4j.ratelimiter.configure.ReactorRateLimiterAspectExt; -import io.github.resilience4j.ratelimiter.configure.RxJava2RateLimiterAspectExt; -import io.github.resilience4j.ratelimiter.event.RateLimiterEvent; -import io.github.resilience4j.fallback.FallbackDecorators; -import io.github.resilience4j.fallback.autoconfigure.FallbackConfigurationOnMissingBean; -import io.github.resilience4j.utils.ReactorOnClasspathCondition; -import io.github.resilience4j.utils.RxJava2OnClasspathCondition; +import java.util.List; @Configuration @Import(FallbackConfigurationOnMissingBean.class) @@ -55,20 +50,21 @@ public RateLimiterRegistry rateLimiterRegistry(RateLimiterConfigurationPropertie } @Bean + @Conditional(value = {AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean public RateLimiterAspect rateLimiterAspect(RateLimiterConfigurationProperties rateLimiterProperties, RateLimiterRegistry rateLimiterRegistry, @Autowired(required = false) List rateLimiterAspectExtList, FallbackDecorators fallbackDecorators) { return rateLimiterConfiguration.rateLimiterAspect(rateLimiterProperties, rateLimiterRegistry, rateLimiterAspectExtList, fallbackDecorators); } @Bean - @Conditional(value = {RxJava2OnClasspathCondition.class}) + @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean - public RxJava2RateLimiterAspectExt rxJava2RateLimterAspectExt() { - return rateLimiterConfiguration.rxJava2RateLimterAspectExt(); + public RxJava2RateLimiterAspectExt rxJava2RateLimiterAspectExt() { + return rateLimiterConfiguration.rxJava2RateLimiterAspectExt(); } @Bean - @Conditional(value = {ReactorOnClasspathCondition.class}) + @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean public ReactorRateLimiterAspectExt reactorRateLimiterAspectExt() { return rateLimiterConfiguration.reactorRateLimiterAspectExt(); diff --git a/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/retry/autoconfigure/AbstractRetryConfigurationOnMissingBean.java b/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/retry/autoconfigure/AbstractRetryConfigurationOnMissingBean.java index 791bb823d9..c3719eb7ae 100644 --- a/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/retry/autoconfigure/AbstractRetryConfigurationOnMissingBean.java +++ b/resilience4j-spring-boot-common/src/main/java/io/github/resilience4j/retry/autoconfigure/AbstractRetryConfigurationOnMissingBean.java @@ -15,28 +15,23 @@ */ package io.github.resilience4j.retry.autoconfigure; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - import io.github.resilience4j.consumer.EventConsumerRegistry; import io.github.resilience4j.fallback.FallbackDecorators; import io.github.resilience4j.fallback.autoconfigure.FallbackConfigurationOnMissingBean; import io.github.resilience4j.retry.RetryRegistry; -import io.github.resilience4j.retry.configure.ReactorRetryAspectExt; -import io.github.resilience4j.retry.configure.RetryAspect; -import io.github.resilience4j.retry.configure.RetryAspectExt; -import io.github.resilience4j.retry.configure.RetryConfiguration; -import io.github.resilience4j.retry.configure.RetryConfigurationProperties; -import io.github.resilience4j.retry.configure.RxJava2RetryAspectExt; +import io.github.resilience4j.retry.configure.*; import io.github.resilience4j.retry.event.RetryEvent; +import io.github.resilience4j.utils.AspectJOnClasspathCondition; import io.github.resilience4j.utils.ReactorOnClasspathCondition; import io.github.resilience4j.utils.RxJava2OnClasspathCondition; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +import java.util.List; /** * {@link Configuration @@ -69,6 +64,7 @@ public RetryRegistry retryRegistry(RetryConfigurationProperties retryConfigurati * @return the spring retry AOP aspect */ @Bean + @Conditional(value = {AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean public RetryAspect retryAspect(RetryConfigurationProperties retryConfigurationProperties, RetryRegistry retryRegistry, @Autowired(required = false) List retryAspectExtList, @@ -77,14 +73,14 @@ public RetryAspect retryAspect(RetryConfigurationProperties retryConfigurationPr } @Bean - @Conditional(value = {RxJava2OnClasspathCondition.class}) + @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean public RxJava2RetryAspectExt rxJava2RetryAspectExt() { return retryConfiguration.rxJava2RetryAspectExt(); } @Bean - @Conditional(value = {ReactorOnClasspathCondition.class}) + @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) @ConditionalOnMissingBean public ReactorRetryAspectExt reactorRetryAspectExt() { return retryConfiguration.reactorRetryAspectExt(); diff --git a/resilience4j-spring-boot-common/src/test/java/io/github/resilience4j/SpringBootCommonTest.java b/resilience4j-spring-boot-common/src/test/java/io/github/resilience4j/SpringBootCommonTest.java index 20609da998..11ba72d6ab 100644 --- a/resilience4j-spring-boot-common/src/test/java/io/github/resilience4j/SpringBootCommonTest.java +++ b/resilience4j-spring-boot-common/src/test/java/io/github/resilience4j/SpringBootCommonTest.java @@ -77,7 +77,7 @@ public void testRetryCommonConfig() { public void testRateLimiterCommonConfig() { RateLimiterConfigurationOnMissingBean rateLimiterConfigurationOnMissingBean = new RateLimiterConfigurationOnMissingBean(); assertThat(rateLimiterConfigurationOnMissingBean.reactorRateLimiterAspectExt()).isNotNull(); - assertThat(rateLimiterConfigurationOnMissingBean.rxJava2RateLimterAspectExt()).isNotNull(); + assertThat(rateLimiterConfigurationOnMissingBean.rxJava2RateLimiterAspectExt()).isNotNull(); assertThat(rateLimiterConfigurationOnMissingBean.rateLimiterRegistry(new RateLimiterConfigurationProperties(), new DefaultEventConsumerRegistry<>())).isNotNull(); assertThat(rateLimiterConfigurationOnMissingBean.rateLimiterAspect(new RateLimiterConfigurationProperties(), RateLimiterRegistry.ofDefaults(), Collections.emptyList(), new FallbackDecorators(Arrays.asList(new CompletionStageFallbackDecorator())))); } diff --git a/resilience4j-spring/src/main/java/io/github/resilience4j/bulkhead/configure/BulkheadConfiguration.java b/resilience4j-spring/src/main/java/io/github/resilience4j/bulkhead/configure/BulkheadConfiguration.java index e651620672..331df012f2 100644 --- a/resilience4j-spring/src/main/java/io/github/resilience4j/bulkhead/configure/BulkheadConfiguration.java +++ b/resilience4j-spring/src/main/java/io/github/resilience4j/bulkhead/configure/BulkheadConfiguration.java @@ -15,17 +15,6 @@ */ package io.github.resilience4j.bulkhead.configure; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - import io.github.resilience4j.bulkhead.Bulkhead; import io.github.resilience4j.bulkhead.BulkheadConfig; import io.github.resilience4j.bulkhead.BulkheadRegistry; @@ -36,8 +25,19 @@ import io.github.resilience4j.consumer.EventConsumerRegistry; import io.github.resilience4j.fallback.FallbackDecorators; import io.github.resilience4j.fallback.configure.FallbackConfiguration; +import io.github.resilience4j.utils.AspectJOnClasspathCondition; import io.github.resilience4j.utils.ReactorOnClasspathCondition; import io.github.resilience4j.utils.RxJava2OnClasspathCondition; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; /** * {@link Configuration @@ -94,6 +94,7 @@ private void registerEventConsumer(EventConsumerRegistry eventCon } @Bean + @Conditional(value = {AspectJOnClasspathCondition.class}) public BulkheadAspect bulkheadAspect(BulkheadConfigurationProperties bulkheadConfigurationProperties, ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry, BulkheadRegistry bulkheadRegistry, @Autowired(required = false) List bulkHeadAspectExtList, FallbackDecorators fallbackDecorators) { @@ -101,13 +102,13 @@ public BulkheadAspect bulkheadAspect(BulkheadConfigurationProperties bulkheadCon } @Bean - @Conditional(value = {RxJava2OnClasspathCondition.class}) + @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) public RxJava2BulkheadAspectExt rxJava2BulkHeadAspectExt() { return new RxJava2BulkheadAspectExt(); } @Bean - @Conditional(value = {ReactorOnClasspathCondition.class}) + @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) public ReactorBulkheadAspectExt reactorBulkHeadAspectExt() { return new ReactorBulkheadAspectExt(); } diff --git a/resilience4j-spring/src/main/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfiguration.java b/resilience4j-spring/src/main/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfiguration.java index b12295c385..dd40cc6495 100644 --- a/resilience4j-spring/src/main/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfiguration.java +++ b/resilience4j-spring/src/main/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfiguration.java @@ -15,15 +15,6 @@ */ package io.github.resilience4j.circuitbreaker.configure; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; - import io.github.resilience4j.circuitbreaker.CircuitBreaker; import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; @@ -31,8 +22,17 @@ import io.github.resilience4j.consumer.DefaultEventConsumerRegistry; import io.github.resilience4j.consumer.EventConsumerRegistry; import io.github.resilience4j.fallback.FallbackDecorators; +import io.github.resilience4j.utils.AspectJOnClasspathCondition; import io.github.resilience4j.utils.ReactorOnClasspathCondition; import io.github.resilience4j.utils.RxJava2OnClasspathCondition; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * {@link org.springframework.context.annotation.Configuration @@ -56,6 +56,7 @@ public CircuitBreakerRegistry circuitBreakerRegistry(EventConsumerRegistry circuitBreakerAspectExtList, FallbackDecorators fallbackDecorators) { @@ -64,13 +65,13 @@ public CircuitBreakerAspect circuitBreakerAspect(CircuitBreakerRegistry circuitB @Bean - @Conditional(value = {RxJava2OnClasspathCondition.class}) + @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) public RxJava2CircuitBreakerAspectExt rxJava2CircuitBreakerAspect() { return new RxJava2CircuitBreakerAspectExt(); } @Bean - @Conditional(value = {ReactorOnClasspathCondition.class}) + @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) public ReactorCircuitBreakerAspectExt reactorCircuitBreakerAspect() { return new ReactorCircuitBreakerAspectExt(); } diff --git a/resilience4j-spring/src/main/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfiguration.java b/resilience4j-spring/src/main/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfiguration.java index e95ed0e817..65dc876a1b 100644 --- a/resilience4j-spring/src/main/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfiguration.java +++ b/resilience4j-spring/src/main/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfiguration.java @@ -16,15 +16,6 @@ package io.github.resilience4j.ratelimiter.configure; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; - import io.github.resilience4j.consumer.DefaultEventConsumerRegistry; import io.github.resilience4j.consumer.EventConsumerRegistry; import io.github.resilience4j.fallback.FallbackDecorators; @@ -32,8 +23,17 @@ import io.github.resilience4j.ratelimiter.RateLimiterConfig; import io.github.resilience4j.ratelimiter.RateLimiterRegistry; import io.github.resilience4j.ratelimiter.event.RateLimiterEvent; +import io.github.resilience4j.utils.AspectJOnClasspathCondition; import io.github.resilience4j.utils.ReactorOnClasspathCondition; import io.github.resilience4j.utils.RxJava2OnClasspathCondition; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * {@link org.springframework.context.annotation.Configuration @@ -86,18 +86,19 @@ private void registerEventConsumer(EventConsumerRegistry event } @Bean + @Conditional(value = {AspectJOnClasspathCondition.class}) public RateLimiterAspect rateLimiterAspect(RateLimiterConfigurationProperties rateLimiterProperties, RateLimiterRegistry rateLimiterRegistry, @Autowired(required = false) List rateLimiterAspectExtList, FallbackDecorators fallbackDecorators) { return new RateLimiterAspect(rateLimiterRegistry, rateLimiterProperties, rateLimiterAspectExtList, fallbackDecorators); } @Bean - @Conditional(value = {RxJava2OnClasspathCondition.class}) - public RxJava2RateLimiterAspectExt rxJava2RateLimterAspectExt() { + @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) + public RxJava2RateLimiterAspectExt rxJava2RateLimiterAspectExt() { return new RxJava2RateLimiterAspectExt(); } @Bean - @Conditional(value = {ReactorOnClasspathCondition.class}) + @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) public ReactorRateLimiterAspectExt reactorRateLimiterAspectExt() { return new ReactorRateLimiterAspectExt(); } diff --git a/resilience4j-spring/src/main/java/io/github/resilience4j/retry/configure/RetryConfiguration.java b/resilience4j-spring/src/main/java/io/github/resilience4j/retry/configure/RetryConfiguration.java index 746c39622b..c4ab2b72c5 100644 --- a/resilience4j-spring/src/main/java/io/github/resilience4j/retry/configure/RetryConfiguration.java +++ b/resilience4j-spring/src/main/java/io/github/resilience4j/retry/configure/RetryConfiguration.java @@ -15,16 +15,6 @@ */ package io.github.resilience4j.retry.configure; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; - import io.github.resilience4j.consumer.DefaultEventConsumerRegistry; import io.github.resilience4j.consumer.EventConsumerRegistry; import io.github.resilience4j.fallback.FallbackDecorators; @@ -32,8 +22,18 @@ import io.github.resilience4j.retry.RetryConfig; import io.github.resilience4j.retry.RetryRegistry; import io.github.resilience4j.retry.event.RetryEvent; +import io.github.resilience4j.utils.AspectJOnClasspathCondition; import io.github.resilience4j.utils.ReactorOnClasspathCondition; import io.github.resilience4j.utils.RxJava2OnClasspathCondition; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; /** * {@link Configuration @@ -95,6 +95,7 @@ private void registerEventConsumer(EventConsumerRegistry eventConsum * @return the spring retry AOP aspect */ @Bean + @Conditional(value = {AspectJOnClasspathCondition.class}) public RetryAspect retryAspect(RetryConfigurationProperties retryConfigurationProperties, RetryRegistry retryRegistry, @Autowired(required = false) List retryAspectExtList, FallbackDecorators fallbackDecorators) { @@ -102,13 +103,13 @@ public RetryAspect retryAspect(RetryConfigurationProperties retryConfigurationPr } @Bean - @Conditional(value = {RxJava2OnClasspathCondition.class}) + @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) public RxJava2RetryAspectExt rxJava2RetryAspectExt() { return new RxJava2RetryAspectExt(); } @Bean - @Conditional(value = {ReactorOnClasspathCondition.class}) + @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) public ReactorRetryAspectExt reactorRetryAspectExt() { return new ReactorRetryAspectExt(); } diff --git a/resilience4j-spring/src/main/java/io/github/resilience4j/utils/AspectJOnClasspathCondition.java b/resilience4j-spring/src/main/java/io/github/resilience4j/utils/AspectJOnClasspathCondition.java new file mode 100644 index 0000000000..6066584312 --- /dev/null +++ b/resilience4j-spring/src/main/java/io/github/resilience4j/utils/AspectJOnClasspathCondition.java @@ -0,0 +1,33 @@ +/* + * Copyright 2019 Robert Winkler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.github.resilience4j.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +public class AspectJOnClasspathCondition implements Condition { + + private static final Logger logger = LoggerFactory.getLogger(AspectJOnClasspathCondition.class); + private static final String CLASS_TO_CHECK = "org.aspectj.lang.ProceedingJoinPoint"; + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + return AspectUtil.checkClassIfFound(context, CLASS_TO_CHECK, (e) -> logger.info("Aspects are not activated because AspectJ is not on the classpath.")); + } + +}