From b33671239bf0b2b0efcd77a95bd7920f52425878 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Mon, 18 Apr 2022 14:04:52 -0400 Subject: [PATCH 1/3] JDK17; Spring Framework 6.0.0-SNAPSHOT Defer fetching RetryListener beans due to `BeanCurrentlyInCreationException` with modern Spring Framework. See gh-286 --- pom.xml | 4 ++-- .../retry/annotation/RetryConfiguration.java | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 878e7c9..2188899 100644 --- a/pom.xml +++ b/pom.xml @@ -28,12 +28,12 @@ 2.0.0-SNAPSHOT false - 1.8 + 17 true UTF-8 UTF-8 - 4.3.29.RELEASE + 6.0.0-SNAPSHOT diff --git a/src/main/java/org/springframework/retry/annotation/RetryConfiguration.java b/src/main/java/org/springframework/retry/annotation/RetryConfiguration.java index dac3cb5..44af456 100644 --- a/src/main/java/org/springframework/retry/annotation/RetryConfiguration.java +++ b/src/main/java/org/springframework/retry/annotation/RetryConfiguration.java @@ -39,6 +39,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.ListableBeanFactory; +import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Role; import org.springframework.core.OrderComparator; @@ -51,7 +52,6 @@ import org.springframework.retry.policy.RetryContextCache; import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; -import org.springframework.util.ReflectionUtils.MethodCallback; /** * Basic configuration for @Retryable processing. For stateful retry, if @@ -62,6 +62,7 @@ import org.springframework.util.ReflectionUtils.MethodCallback; * @author Dave Syer * @author Artem Bilan * @author Markus Heiden + * @author Gary Russell * @since 1.1 * */ @@ -69,9 +70,9 @@ import org.springframework.util.ReflectionUtils.MethodCallback; @Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Component public class RetryConfiguration extends AbstractPointcutAdvisor - implements IntroductionAdvisor, BeanFactoryAware, InitializingBean { + implements IntroductionAdvisor, BeanFactoryAware, InitializingBean, SmartInitializingSingleton { - private Advice advice; + private AnnotationAwareRetryOperationsInterceptor advice; private Pointcut pointcut; @@ -92,7 +93,6 @@ public class RetryConfiguration extends AbstractPointcutAdvisor this.retryContextCache = findBean(RetryContextCache.class); this.methodArgumentsKeyGenerator = findBean(MethodArgumentsKeyGenerator.class); this.newMethodArgumentsIdentifier = findBean(NewMethodArgumentsIdentifier.class); - this.retryListeners = findBeans(RetryListener.class); this.sleeper = findBean(Sleeper.class); Set> retryableAnnotationTypes = new LinkedHashSet<>(1); retryableAnnotationTypes.add(Retryable.class); @@ -103,6 +103,14 @@ public class RetryConfiguration extends AbstractPointcutAdvisor } } + @Override + public void afterSingletonsInstantiated() { + this.retryListeners = findBeans(RetryListener.class); + if (this.retryListeners != null) { + this.advice.setListeners(this.retryListeners); + } + } + private List findBeans(Class type) { if (this.beanFactory instanceof ListableBeanFactory) { ListableBeanFactory listable = (ListableBeanFactory) this.beanFactory; @@ -157,14 +165,11 @@ public class RetryConfiguration extends AbstractPointcutAdvisor return this.pointcut; } - protected Advice buildAdvice() { + protected AnnotationAwareRetryOperationsInterceptor buildAdvice() { AnnotationAwareRetryOperationsInterceptor interceptor = new AnnotationAwareRetryOperationsInterceptor(); if (this.retryContextCache != null) { interceptor.setRetryContextCache(this.retryContextCache); } - if (this.retryListeners != null) { - interceptor.setListeners(this.retryListeners); - } if (this.methodArgumentsKeyGenerator != null) { interceptor.setKeyGenerator(this.methodArgumentsKeyGenerator); } From 3398f8feab5dbbe158081e9f7380c4611f8b17d4 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Mon, 18 Apr 2022 14:35:18 -0400 Subject: [PATCH 2/3] Switch to Java 17 on CI See gh-286 --- ci/images/ci-image/Dockerfile | 4 ++-- ci/images/get-jdk-url.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/images/ci-image/Dockerfile b/ci/images/ci-image/Dockerfile index 4e4e318..b97697d 100644 --- a/ci/images/ci-image/Dockerfile +++ b/ci/images/ci-image/Dockerfile @@ -2,7 +2,7 @@ FROM ubuntu:focal-20220404 ADD setup.sh /setup.sh ADD get-jdk-url.sh /get-jdk-url.sh -RUN ./setup.sh java8 +RUN ./setup.sh java17 ENV JAVA_HOME /opt/openjdk -ENV PATH $JAVA_HOME/bin:$PATH \ No newline at end of file +ENV PATH $JAVA_HOME/bin:$PATH diff --git a/ci/images/get-jdk-url.sh b/ci/images/get-jdk-url.sh index f71d8e1..6f4c153 100755 --- a/ci/images/get-jdk-url.sh +++ b/ci/images/get-jdk-url.sh @@ -2,8 +2,8 @@ set -e case "$1" in - java8) - echo "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u322-b06/OpenJDK8U-jdk_x64_linux_hotspot_8u322b06.tar.gz" + java17) + echo "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2%2B8/OpenJDK17U-jdk_x64_linux_hotspot_17.0.2_8.tar.gz" ;; *) echo $"Unknown java version" From 68a4bd08ffd2d361b2fb6db1e756c4153695065c Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 19 Apr 2022 08:32:21 +0200 Subject: [PATCH 3/3] Polish contribution See gh-286 --- ci/images/ci-image/Dockerfile | 2 +- ci/images/get-jdk-url.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/images/ci-image/Dockerfile b/ci/images/ci-image/Dockerfile index b97697d..14ed95c 100644 --- a/ci/images/ci-image/Dockerfile +++ b/ci/images/ci-image/Dockerfile @@ -5,4 +5,4 @@ ADD get-jdk-url.sh /get-jdk-url.sh RUN ./setup.sh java17 ENV JAVA_HOME /opt/openjdk -ENV PATH $JAVA_HOME/bin:$PATH +ENV PATH $JAVA_HOME/bin:$PATH \ No newline at end of file diff --git a/ci/images/get-jdk-url.sh b/ci/images/get-jdk-url.sh index 6f4c153..ccaf002 100755 --- a/ci/images/get-jdk-url.sh +++ b/ci/images/get-jdk-url.sh @@ -3,7 +3,7 @@ set -e case "$1" in java17) - echo "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2%2B8/OpenJDK17U-jdk_x64_linux_hotspot_17.0.2_8.tar.gz" + echo "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2%2B8/OpenJDK17U-jdk_x64_linux_hotspot_17.0.2_8.tar.gz" ;; *) echo $"Unknown java version"