Skip to content

Commit 28c9761

Browse files
committed
Polish reflection hints on bean registration interfaces
This commit ensures that we register reflection hints on interfaces in the entire type hierarchy, including extended interfaces. Closes gh-31350
1 parent 74fc8bd commit 28c9761

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,21 @@ private void generateRegisterHints(RuntimeHints runtimeHints, Map<BeanRegistrati
115115
ReflectionHints hints = runtimeHints.reflection();
116116
Class<?> beanClass = beanRegistrationKey.beanClass();
117117
hints.registerType(beanClass, MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS);
118-
Class<?> currentClass = beanClass;
119-
while (currentClass != null && currentClass != Object.class) {
120-
for (Class<?> interfaceType : currentClass.getInterfaces()) {
121-
if (!ClassUtils.isJavaLanguageInterface(interfaceType)) {
122-
hints.registerType(interfaceType, MemberCategory.INTROSPECT_PUBLIC_METHODS);
123-
}
118+
introspectPublicMethodsOnAllInterfaces(hints, beanClass);
119+
});
120+
}
121+
122+
private void introspectPublicMethodsOnAllInterfaces(ReflectionHints hints, Class<?> type) {
123+
Class<?> currentClass = type;
124+
while (currentClass != null && currentClass != Object.class) {
125+
for (Class<?> interfaceType : currentClass.getInterfaces()) {
126+
if (!ClassUtils.isJavaLanguageInterface(interfaceType)) {
127+
hints.registerType(interfaceType, MemberCategory.INTROSPECT_PUBLIC_METHODS);
128+
introspectPublicMethodsOnAllInterfaces(hints, interfaceType);
124129
}
125-
currentClass = currentClass.getSuperclass();
126130
}
127-
});
131+
currentClass = currentClass.getSuperclass();
132+
}
128133
}
129134

130135
/**

spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
3737
import org.springframework.beans.factory.support.RegisteredBean;
3838
import org.springframework.beans.factory.support.RootBeanDefinition;
39+
import org.springframework.beans.testfixture.beans.AgeHolder;
3940
import org.springframework.beans.testfixture.beans.Employee;
4041
import org.springframework.beans.testfixture.beans.ITestBean;
4142
import org.springframework.beans.testfixture.beans.TestBean;
@@ -151,6 +152,9 @@ void applyToRegisterReflectionHints() {
151152
assertThat(reflection().onType(ITestBean.class)
152153
.withMemberCategory(MemberCategory.INTROSPECT_PUBLIC_METHODS))
153154
.accepts(this.generationContext.getRuntimeHints());
155+
assertThat(reflection().onType(AgeHolder.class)
156+
.withMemberCategory(MemberCategory.INTROSPECT_PUBLIC_METHODS))
157+
.accepts(this.generationContext.getRuntimeHints());
154158
}
155159

156160
private RegisteredBean registerBean(RootBeanDefinition rootBeanDefinition) {

0 commit comments

Comments
 (0)