JDK17; Spring Framework 6.0.0-SNAPSHOT
Defer fetching RetryListener beans due to `BeanCurrentlyInCreationException` with modern Spring Framework. See gh-286
This commit is contained in:
committed by
Stephane Nicoll
parent
4b3f8506a4
commit
b33671239b
4
pom.xml
4
pom.xml
@@ -28,12 +28,12 @@
|
||||
<properties>
|
||||
<revision>2.0.0-SNAPSHOT</revision>
|
||||
<disable.checks>false</disable.checks>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>17</java.version>
|
||||
<maven.test.failure.ignore>true</maven.test.failure.ignore>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<spring.framework.version>4.3.29.RELEASE</spring.framework.version>
|
||||
<spring.framework.version>6.0.0-SNAPSHOT</spring.framework.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
|
||||
@@ -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 <code>@Retryable</code> 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<Class<? extends Annotation>> 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 <T> List<T> findBeans(Class<? extends T> 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user