Skip to content

Commit 19c26ba

Browse files
Move reflection hint handling to repository context.
See: #3267 Original Pull Request: #3367
1 parent 3fc2cb9 commit 19c26ba

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/main/java/org/springframework/data/aot/DefaultAotContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.aot.generate.GenerationContext;
3434
import org.springframework.aot.hint.MemberCategory;
3535
import org.springframework.aot.hint.TypeReference;
36+
import org.springframework.aot.hint.annotation.ReflectiveRuntimeHintsRegistrar;
3637
import org.springframework.beans.factory.BeanFactory;
3738
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
3839
import org.springframework.beans.factory.aot.AotProcessingException;
@@ -63,6 +64,7 @@ class DefaultAotContext implements AotContext {
6364

6465
private final Map<Class<?>, ContextualTypeConfiguration> typeConfigurations = new HashMap<>();
6566
private final Environment environment;
67+
private final ReflectiveRuntimeHintsRegistrar runtimeHintsRegistrar = new ReflectiveRuntimeHintsRegistrar();
6668

6769
public DefaultAotContext(BeanFactory beanFactory, Environment environment) {
6870
this(beanFactory, environment, new AotMappingContext());
@@ -257,6 +259,7 @@ private void doContribute(Environment environment, GenerationContext generationC
257259
}
258260

259261
if (forDataBinding) {
262+
runtimeHintsRegistrar.registerRuntimeHints(generationContext.getRuntimeHints(), type);
260263
TypeContributor.contribute(type, Set.of(TypeContributor.DATA_NAMESPACE), generationContext);
261264
}
262265

src/main/java/org/springframework/data/aot/ManagedTypesBeanRegistrationAotProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ protected void registerTypeHints(ResolvableType type, AotContext aotContext, Gen
155155

156156
Set<String> annotationNamespaces = Collections.singleton(TypeContributor.DATA_NAMESPACE);
157157

158-
configureTypeHints(type.toClass(), aotContext);
158+
configureTypeContribution(type.toClass(), aotContext);
159159

160160
TypeUtils.resolveUsedAnnotations(type.toClass()).forEach(
161161
annotation -> TypeContributor.contribute(annotation.getType(), annotationNamespaces, generationContext));
@@ -168,7 +168,7 @@ protected void registerTypeHints(ResolvableType type, AotContext aotContext, Gen
168168
* @param aotContext AOT context for type configuration.
169169
* @since 4.0
170170
*/
171-
protected void configureTypeHints(Class<?> type, AotContext aotContext) {
171+
protected void configureTypeContribution(Class<?> type, AotContext aotContext) {
172172
aotContext.typeConfiguration(type, config -> config.forDataBinding().contributeAccessors().forQuerydsl());
173173
}
174174

src/main/java/org/springframework/data/repository/config/RepositoryRegistrationAotProcessor.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@
2626
import org.apache.commons.logging.Log;
2727
import org.apache.commons.logging.LogFactory;
2828
import org.jspecify.annotations.Nullable;
29-
3029
import org.springframework.aot.generate.GenerationContext;
3130
import org.springframework.aot.hint.MemberCategory;
32-
import org.springframework.aot.hint.RuntimeHints;
3331
import org.springframework.aot.hint.TypeReference;
34-
import org.springframework.aot.hint.annotation.ReflectiveRuntimeHintsRegistrar;
3532
import org.springframework.beans.BeansException;
3633
import org.springframework.beans.factory.BeanFactory;
3734
import org.springframework.beans.factory.BeanFactoryAware;
@@ -216,7 +213,8 @@ protected void registerRepositoryCompositionHints(AotRepositoryContext repositor
216213
* @param generationContext the generation context.
217214
* @since 4.0
218215
*/
219-
private void configureTypeContributions(AotRepositoryContext repositoryContext, GenerationContext generationContext) {
216+
protected void configureTypeContributions(AotRepositoryContext repositoryContext,
217+
GenerationContext generationContext) {
220218

221219
RepositoryInformation information = repositoryContext.getRepositoryInformation();
222220

@@ -246,22 +244,17 @@ private void configureTypeContributions(AotRepositoryContext repositoryContext,
246244
* @param generationContext the generation context.
247245
* @since 4.0
248246
*/
249-
protected void configureDomainTypeContributions(AotRepositoryContext repositoryContext,
247+
private void configureDomainTypeContributions(AotRepositoryContext repositoryContext,
250248
GenerationContext generationContext) {
251249

252250
RepositoryInformation information = repositoryContext.getRepositoryInformation();
253-
RuntimeHints hints = generationContext.getRuntimeHints();
254251

255-
// Domain types, related types, projections
256-
ReflectiveRuntimeHintsRegistrar registrar = new ReflectiveRuntimeHintsRegistrar();
257252
Stream.concat(Stream.of(information.getDomainType()), information.getAlternativeDomainTypes().stream())
258253
.forEach(it -> {
259-
260-
registrar.registerRuntimeHints(hints, it);
261254
configureTypeContribution(it, repositoryContext);
262255
});
263256

264-
// TODO: Looks like a duplicate
257+
// Domain types my be part of this, but it also contains reachable ones.
265258
repositoryContext.getResolvedTypes().stream()
266259
.filter(it -> TypeContributor.isPartOf(it, Set.of(information.getDomainType().getPackageName())))
267260
.forEach(it -> configureTypeContribution(it, repositoryContext));

0 commit comments

Comments
 (0)