Skip to content

Commit b832df6

Browse files
committed
Add reflection hints for bean registration interfaces
Prior to this commit, the bean registration AOT contributions would register introspection and invocation hints on both declared and public methods for bean types. The bean introspection algorithm also looks at default methods implemented by interfaces when collecting bean property information. This commit ensures that introspection hints are registered for all implemented interfaces when registering beans. Closes gh-31350
1 parent c45bf3c commit b832df6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ private void generateRegisterHints(RuntimeHints runtimeHints, Map<BeanRegistrati
118118
ReflectionHints hints = runtimeHints.reflection();
119119
Class<?> beanClass = beanRegistrationKey.beanClass();
120120
hints.registerType(beanClass, MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS);
121+
for (Class<?> interfaceType : beanClass.getInterfaces()) {
122+
hints.registerType(interfaceType, MemberCategory.INTROSPECT_PUBLIC_METHODS);
123+
}
121124
// Workaround for https://github.com/oracle/graal/issues/6510
122125
if (beanClass.isRecord()) {
123126
hints.registerType(beanClass, MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS);

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

+5
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ void applyToRegisterReflectionHints() {
149149
assertThat(reflection().onType(TestBean.class)
150150
.withMemberCategories(MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS))
151151
.accepts(this.generationContext.getRuntimeHints());
152+
for (Class<?> interfaceType : TestBean.class.getInterfaces()) {
153+
assertThat(reflection().onType(interfaceType)
154+
.withMemberCategory(MemberCategory.INTROSPECT_PUBLIC_METHODS))
155+
.accepts(this.generationContext.getRuntimeHints());
156+
}
152157
}
153158

154159
@Test

0 commit comments

Comments
 (0)