68
68
* @author John Blum
69
69
* @author Christoph Strobl
70
70
* @author Mark Paluch
71
- * @see org.springframework.beans.factory.aot.BeanRegistrationAotContribution
72
71
* @since 3.0
72
+ * @see org.springframework.beans.factory.aot.BeanRegistrationAotContribution
73
73
*/
74
74
class ManagedTypesRegistrationAotContribution implements RegisteredBeanAotContribution {
75
75
@@ -125,7 +125,7 @@ static class ManagedTypesInstanceCodeFragment extends BeanRegistrationCodeFragme
125
125
public static final ResolvableType MANAGED_TYPES_TYPE = ResolvableType .forType (ManagedTypes .class );
126
126
private final List <Class <?>> sourceTypes ;
127
127
private final RegisteredBean source ;
128
- private final Lazy <Method > instanceMethod = Lazy . of ( this :: findInstanceFactory ) ;
128
+ private final Lazy <Method > instanceMethod ;
129
129
130
130
private static final TypeName WILDCARD = WildcardTypeName .subtypeOf (Object .class );
131
131
private static final TypeName CLASS_OF_ANY = ParameterizedTypeName .get (ClassName .get (Class .class ), WILDCARD );
@@ -138,6 +138,7 @@ protected ManagedTypesInstanceCodeFragment(List<Class<?>> sourceTypes, Registere
138
138
139
139
this .sourceTypes = sourceTypes ;
140
140
this .source = source ;
141
+ this .instanceMethod = Lazy .of (() -> findInstanceFactory (source .getBeanClass ()));
141
142
}
142
143
143
144
@ Override
@@ -229,15 +230,15 @@ private CodeBlock toCodeBlock(List<Class<?>> values, boolean allPublic) {
229
230
}
230
231
231
232
@ Nullable
232
- private Method findInstanceFactory () {
233
+ private static Method findInstanceFactory (Class <?> beanClass ) {
233
234
234
- for (Method beanMethod : ReflectionUtils .getDeclaredMethods (source . getBeanClass () )) {
235
+ for (Method beanMethod : ReflectionUtils .getDeclaredMethods (beanClass )) {
235
236
236
237
if (!isInstanceFactory (beanMethod )) {
237
238
continue ;
238
239
}
239
240
240
- ResolvableType parameterType = ResolvableType .forMethodParameter (beanMethod , 0 , source . getBeanClass () );
241
+ ResolvableType parameterType = ResolvableType .forMethodParameter (beanMethod , 0 , beanClass );
241
242
242
243
if (parameterType .isAssignableFrom (LIST_TYPE ) || parameterType .isAssignableFrom (MANAGED_TYPES_TYPE )) {
243
244
return beanMethod ;
0 commit comments