From b832df60873fd528fba369dbb72a6a86274a1718 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 2 Oct 2023 19:33:05 +0200 Subject: [PATCH] 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 --- .../beans/factory/aot/BeanRegistrationsAotContribution.java | 3 +++ .../factory/aot/BeanRegistrationsAotContributionTests.java | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java index 0cc914fc599..58f66ddaaac 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java @@ -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); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java index f5869000218..eb58f97a8a9 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java @@ -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