40
40
import org .springframework .core .annotation .MergedAnnotation ;
41
41
import org .springframework .core .annotation .MergedAnnotations ;
42
42
import org .springframework .lang .Nullable ;
43
+ import org .springframework .util .ClassUtils ;
43
44
import org .springframework .util .ReflectionUtils ;
44
45
45
46
/**
48
49
* underlying {@link ReflectiveProcessor} implementations.
49
50
*
50
51
* @author Stephane Nicoll
52
+ * @author Sebastien Deleuze
51
53
*/
52
54
class ReflectiveProcessorBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
53
55
@@ -58,37 +60,44 @@ class ReflectiveProcessorBeanRegistrationAotProcessor implements BeanRegistratio
58
60
public BeanRegistrationAotContribution processAheadOfTime (RegisteredBean registeredBean ) {
59
61
Class <?> beanClass = registeredBean .getBeanClass ();
60
62
Set <Entry > entries = new LinkedHashSet <>();
61
- if (isReflective (beanClass )) {
62
- entries .add (createEntry (beanClass ));
63
+ processType (entries , beanClass );
64
+ for (Class <?> implementedInterface : ClassUtils .getAllInterfacesForClass (beanClass )) {
65
+ processType (entries , implementedInterface );
63
66
}
64
- doWithReflectiveConstructors (beanClass , constructor ->
65
- entries .add (createEntry (constructor )));
66
- ReflectionUtils .doWithFields (beanClass , field ->
67
- entries .add (createEntry (field )), this ::isReflective );
68
- ReflectionUtils .doWithMethods (beanClass , method ->
69
- entries .add (createEntry (method )), this ::isReflective );
70
67
if (!entries .isEmpty ()) {
71
68
return new ReflectiveProcessorBeanRegistrationAotContribution (entries );
72
69
}
73
70
return null ;
74
71
}
75
72
76
- private void doWithReflectiveConstructors (Class <?> beanClass , Consumer <Constructor <?>> consumer ) {
77
- for (Constructor <?> constructor : beanClass .getDeclaredConstructors ()) {
73
+ private void processType (Set <Entry > entries , Class <?> typeToProcess ) {
74
+ if (isReflective (typeToProcess )) {
75
+ entries .add (createEntry (typeToProcess ));
76
+ }
77
+ doWithReflectiveConstructors (typeToProcess , constructor ->
78
+ entries .add (createEntry (constructor )));
79
+ ReflectionUtils .doWithFields (typeToProcess , field ->
80
+ entries .add (createEntry (field )), this ::isReflective );
81
+ ReflectionUtils .doWithMethods (typeToProcess , method ->
82
+ entries .add (createEntry (method )), this ::isReflective );
83
+ }
84
+
85
+ private void doWithReflectiveConstructors (Class <?> typeToProcess , Consumer <Constructor <?>> consumer ) {
86
+ for (Constructor <?> constructor : typeToProcess .getDeclaredConstructors ()) {
78
87
if (isReflective (constructor )) {
79
88
consumer .accept (constructor );
80
89
}
81
90
}
82
91
}
83
92
84
93
private boolean isReflective (AnnotatedElement element ) {
85
- return MergedAnnotations .from (element ).isPresent (Reflective .class );
94
+ return MergedAnnotations .from (element , MergedAnnotations . SearchStrategy . TYPE_HIERARCHY ).isPresent (Reflective .class );
86
95
}
87
96
88
97
@ SuppressWarnings ("unchecked" )
89
98
private Entry createEntry (AnnotatedElement element ) {
90
99
Class <? extends ReflectiveProcessor >[] processorClasses = (Class <? extends ReflectiveProcessor >[])
91
- MergedAnnotations .from (element ).get (Reflective .class ).getClassArray ("value" );
100
+ MergedAnnotations .from (element , MergedAnnotations . SearchStrategy . TYPE_HIERARCHY ).get (Reflective .class ).getClassArray ("value" );
92
101
List <ReflectiveProcessor > processors = Arrays .stream (processorClasses ).distinct ()
93
102
.map (processorClass -> this .processors .computeIfAbsent (processorClass , BeanUtils ::instantiateClass ))
94
103
.toList ();
@@ -125,7 +134,6 @@ public ReflectiveProcessorBeanRegistrationAotContribution(Iterable<Entry> entrie
125
134
@ Override
126
135
public void applyTo (GenerationContext generationContext , BeanRegistrationCode beanRegistrationCode ) {
127
136
RuntimeHints runtimeHints = generationContext .getRuntimeHints ();
128
- RuntimeHintsUtils .registerAnnotation (runtimeHints , Reflective .class );
129
137
this .entries .forEach (entry -> {
130
138
AnnotatedElement element = entry .element ();
131
139
entry .processor ().registerReflectionHints (runtimeHints .reflection (), element );
0 commit comments