11/*
2- * Copyright 2006-2022 the original author or authors.
2+ * Copyright 2006-2023 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
4141import org .springframework .beans .factory .ListableBeanFactory ;
4242import org .springframework .beans .factory .SmartInitializingSingleton ;
4343import org .springframework .beans .factory .config .BeanDefinition ;
44+ import org .springframework .context .annotation .ImportAware ;
4445import org .springframework .context .annotation .Role ;
4546import org .springframework .core .OrderComparator ;
47+ import org .springframework .core .annotation .AnnotationAttributes ;
4648import org .springframework .core .annotation .AnnotationUtils ;
49+ import org .springframework .core .type .AnnotationMetadata ;
50+ import org .springframework .lang .Nullable ;
4751import org .springframework .retry .RetryListener ;
4852import org .springframework .retry .backoff .Sleeper ;
4953import org .springframework .retry .interceptor .MethodArgumentsKeyGenerator ;
6367 * @author Artem Bilan
6468 * @author Markus Heiden
6569 * @author Gary Russell
70+ * @author Yanming Zhou
6671 * @since 1.1
6772 *
6873 */
6974@ SuppressWarnings ("serial" )
7075@ Role (BeanDefinition .ROLE_INFRASTRUCTURE )
7176@ Component
7277public class RetryConfiguration extends AbstractPointcutAdvisor
73- implements IntroductionAdvisor , BeanFactoryAware , InitializingBean , SmartInitializingSingleton {
78+ implements IntroductionAdvisor , BeanFactoryAware , InitializingBean , SmartInitializingSingleton , ImportAware {
79+
80+ @ Nullable
81+ protected AnnotationAttributes enableRetry ;
7482
7583 private AnnotationAwareRetryOperationsInterceptor advice ;
7684
@@ -88,6 +96,12 @@ public class RetryConfiguration extends AbstractPointcutAdvisor
8896
8997 private BeanFactory beanFactory ;
9098
99+ @ Override
100+ public void setImportMetadata (AnnotationMetadata importMetadata ) {
101+ this .enableRetry = AnnotationAttributes
102+ .fromMap (importMetadata .getAnnotationAttributes (EnableRetry .class .getName ()));
103+ }
104+
91105 @ Override
92106 public void afterPropertiesSet () throws Exception {
93107 this .retryContextCache = findBean (RetryContextCache .class );
@@ -98,8 +112,9 @@ public void afterPropertiesSet() throws Exception {
98112 retryableAnnotationTypes .add (Retryable .class );
99113 this .pointcut = buildPointcut (retryableAnnotationTypes );
100114 this .advice = buildAdvice ();
101- if (this .advice instanceof BeanFactoryAware ) {
102- ((BeanFactoryAware ) this .advice ).setBeanFactory (this .beanFactory );
115+ this .advice .setBeanFactory (this .beanFactory );
116+ if (this .enableRetry != null ) {
117+ setOrder (enableRetry .getNumber ("order" ));
103118 }
104119 }
105120
0 commit comments