From 9e9ddbf3346b2b2b1b44b01488b130cd1fbb7be1 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Mon, 5 Sep 2022 10:03:08 +0200 Subject: [PATCH] Use BindingReflectionHintsRegistrar to add reflection hints on types. Closes: #2683 Original pull request: #2684. --- .../aot/RepositoryRegistrationAotContribution.java | 7 +++---- .../springframework/data/aot/TypeContributor.java | 12 +++--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/springframework/data/aot/RepositoryRegistrationAotContribution.java b/src/main/java/org/springframework/data/aot/RepositoryRegistrationAotContribution.java index 1e8fc318d..846ceaceb 100644 --- a/src/main/java/org/springframework/data/aot/RepositoryRegistrationAotContribution.java +++ b/src/main/java/org/springframework/data/aot/RepositoryRegistrationAotContribution.java @@ -268,10 +268,9 @@ public class RepositoryRegistrationAotContribution implements BeanRegistrationAo .registerType(repositoryInformation.getRepositoryInterface(), hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS)) .registerType(repositoryInformation.getRepositoryBaseClass(), - hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS)) - .registerType(repositoryInformation.getDomainType(), - hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, - MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)); + hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS)); + + TypeContributor.contribute(repositoryInformation.getDomainType(), contribution); // Repository Fragments for (RepositoryFragment fragment : getRepositoryInformation().getFragments()) { diff --git a/src/main/java/org/springframework/data/aot/TypeContributor.java b/src/main/java/org/springframework/data/aot/TypeContributor.java index 9993194e4..7641642fc 100644 --- a/src/main/java/org/springframework/data/aot/TypeContributor.java +++ b/src/main/java/org/springframework/data/aot/TypeContributor.java @@ -21,6 +21,7 @@ import java.util.Set; import java.util.function.Predicate; import org.springframework.aot.generate.GenerationContext; +import org.springframework.aot.hint.BindingReflectionHintsRegistrar; import org.springframework.aot.hint.MemberCategory; import org.springframework.core.annotation.MergedAnnotation; @@ -31,6 +32,7 @@ import org.springframework.core.annotation.MergedAnnotation; public class TypeContributor { public static final String DATA_NAMESPACE = "org.springframework.data"; + public static final BindingReflectionHintsRegistrar REGISTRAR = new BindingReflectionHintsRegistrar(); /** * Contribute the type with default reflection configuration, skip annotations. @@ -65,15 +67,7 @@ public class TypeContributor { return; } - if (type.isInterface()) { - contribution.getRuntimeHints().reflection().registerType(type, - hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS)); - return; - } - - contribution.getRuntimeHints().reflection().registerType(type, - hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS, - MemberCategory.DECLARED_FIELDS)); + REGISTRAR.registerReflectionHints(contribution.getRuntimeHints().reflection(), type); } /**