1
1
/*
2
- * Copyright 2006-2022 the original author or authors.
2
+ * Copyright 2006-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
41
41
import org .springframework .beans .factory .ListableBeanFactory ;
42
42
import org .springframework .beans .factory .SmartInitializingSingleton ;
43
43
import org .springframework .beans .factory .config .BeanDefinition ;
44
+ import org .springframework .context .annotation .ImportAware ;
44
45
import org .springframework .context .annotation .Role ;
45
46
import org .springframework .core .OrderComparator ;
47
+ import org .springframework .core .annotation .AnnotationAttributes ;
46
48
import org .springframework .core .annotation .AnnotationUtils ;
49
+ import org .springframework .core .type .AnnotationMetadata ;
50
+ import org .springframework .lang .Nullable ;
47
51
import org .springframework .retry .RetryListener ;
48
52
import org .springframework .retry .backoff .Sleeper ;
49
53
import org .springframework .retry .interceptor .MethodArgumentsKeyGenerator ;
63
67
* @author Artem Bilan
64
68
* @author Markus Heiden
65
69
* @author Gary Russell
70
+ * @author Yanming Zhou
66
71
* @since 1.1
67
72
*
68
73
*/
69
74
@ SuppressWarnings ("serial" )
70
75
@ Role (BeanDefinition .ROLE_INFRASTRUCTURE )
71
76
@ Component
72
77
public class RetryConfiguration extends AbstractPointcutAdvisor
73
- implements IntroductionAdvisor , BeanFactoryAware , InitializingBean , SmartInitializingSingleton {
78
+ implements IntroductionAdvisor , BeanFactoryAware , InitializingBean , SmartInitializingSingleton , ImportAware {
79
+
80
+ @ Nullable
81
+ protected AnnotationAttributes enableRetry ;
74
82
75
83
private AnnotationAwareRetryOperationsInterceptor advice ;
76
84
@@ -88,6 +96,12 @@ public class RetryConfiguration extends AbstractPointcutAdvisor
88
96
89
97
private BeanFactory beanFactory ;
90
98
99
+ @ Override
100
+ public void setImportMetadata (AnnotationMetadata importMetadata ) {
101
+ this .enableRetry = AnnotationAttributes
102
+ .fromMap (importMetadata .getAnnotationAttributes (EnableRetry .class .getName ()));
103
+ }
104
+
91
105
@ Override
92
106
public void afterPropertiesSet () throws Exception {
93
107
this .retryContextCache = findBean (RetryContextCache .class );
@@ -98,8 +112,9 @@ public void afterPropertiesSet() throws Exception {
98
112
retryableAnnotationTypes .add (Retryable .class );
99
113
this .pointcut = buildPointcut (retryableAnnotationTypes );
100
114
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" ));
103
118
}
104
119
}
105
120
0 commit comments