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
This commit is contained in:
Brian Clozel 2023-10-02 19:33:05 +02:00
parent c45bf3c061
commit b832df6087
2 changed files with 8 additions and 0 deletions

View File

@ -118,6 +118,9 @@ 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);
}
// Workaround for https://github.com/oracle/graal/issues/6510
if (beanClass.isRecord()) {
hints.registerType(beanClass, MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS);

View File

@ -149,6 +149,11 @@ class BeanRegistrationsAotContributionTests {
assertThat(reflection().onType(TestBean.class)
.withMemberCategories(MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS))
.accepts(this.generationContext.getRuntimeHints());
for (Class<?> interfaceType : TestBean.class.getInterfaces()) {
assertThat(reflection().onType(interfaceType)
.withMemberCategory(MemberCategory.INTROSPECT_PUBLIC_METHODS))
.accepts(this.generationContext.getRuntimeHints());
}
}
@Test