Polish reflection hints on bean registration interfaces

This commit ensures that we register reflection hints on interfaces in
the entire type hierarchy.

Closes gh-31350
This commit is contained in:
Brian Clozel
2023-10-03 11:24:47 +02:00
parent b832df6087
commit 1fd54912d2
2 changed files with 17 additions and 10 deletions

View File

@@ -36,6 +36,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.javapoet.ClassName;
import org.springframework.javapoet.CodeBlock;
import org.springframework.javapoet.MethodSpec;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
/**
@@ -118,8 +119,14 @@ class BeanRegistrationsAotContribution
ReflectionHints hints = runtimeHints.reflection();
Class<?> beanClass = beanRegistrationKey.beanClass();
hints.registerType(beanClass, MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS);
for (Class<?> interfaceType : beanClass.getInterfaces()) {
hints.registerType(interfaceType, MemberCategory.INTROSPECT_PUBLIC_METHODS);
Class<?> currentClass = beanClass;
while (currentClass != null && currentClass != Object.class) {
for (Class<?> interfaceType : currentClass.getInterfaces()) {
if (!ClassUtils.isJavaLanguageInterface(interfaceType)) {
hints.registerType(interfaceType, MemberCategory.INTROSPECT_PUBLIC_METHODS);
}
}
currentClass = currentClass.getSuperclass();
}
// Workaround for https://github.com/oracle/graal/issues/6510
if (beanClass.isRecord()) {