Skip to content

Commit 645baab

Browse files
Add AOT proxy hints for CrudMethodMetadata.
Closes: #4534
1 parent 02c6d33 commit 645baab

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/RepositoryRuntimeHints.java

+15
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2525
import org.springframework.aot.hint.TypeReference;
2626
import org.springframework.data.mongodb.aot.MongoAotPredicates;
27+
import org.springframework.data.mongodb.repository.support.CrudMethodMetadata;
2728
import org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor;
2829
import org.springframework.data.mongodb.repository.support.ReactiveQuerydslMongoPredicateExecutor;
2930
import org.springframework.data.querydsl.QuerydslUtils;
3031
import org.springframework.lang.Nullable;
32+
import org.springframework.util.ClassUtils;
3133

3234
/**
3335
* @author Christoph Strobl
@@ -43,6 +45,15 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
4345
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
4446
MemberCategory.INVOKE_PUBLIC_METHODS));
4547

48+
if (isAopPresent(classLoader)) {
49+
50+
// required for pushing ReadPreference,... into the default repository implementation
51+
hints.proxies().registerJdkProxy(CrudMethodMetadata.class, //
52+
org.springframework.aop.SpringProxy.class, //
53+
org.springframework.aop.framework.Advised.class, //
54+
org.springframework.core.DecoratingProxy.class);
55+
}
56+
4657
if (isReactorPresent()) {
4758

4859
hints.reflection().registerTypes(
@@ -77,4 +88,8 @@ private static void registerQuerydslHints(RuntimeHints hints, @Nullable ClassLoa
7788
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
7889
}
7990
}
91+
92+
private static boolean isAopPresent(@Nullable ClassLoader classLoader) {
93+
return ClassUtils.isPresent("org.springframework.aop.Pointcut", classLoader);
94+
}
8095
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/aot/RepositoryRuntimeHintsUnitTests.java

+13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.aot.hint.RuntimeHints;
2323
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
2424
import org.springframework.data.mongodb.classloading.HidingClassLoader;
25+
import org.springframework.data.mongodb.repository.support.CrudMethodMetadata;
2526
import org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor;
2627
import org.springframework.data.mongodb.repository.support.ReactiveQuerydslMongoPredicateExecutor;
2728

@@ -64,4 +65,16 @@ void doesNotRegistersReactiveTypesForQuerydslIntegrationWhenReactorNotPresent()
6465
assertThat(runtimeHints).matches(RuntimeHintsPredicates.reflection().onType(QuerydslMongoPredicateExecutor.class)
6566
.and(RuntimeHintsPredicates.reflection().onType(ReactiveQuerydslMongoPredicateExecutor.class).negate()));
6667
}
68+
69+
@Test // GH-2971, GH-4534
70+
void registersProxyForCrudMethodMetadata() {
71+
72+
RuntimeHints runtimeHints = new RuntimeHints();
73+
new RepositoryRuntimeHints().registerHints(runtimeHints, null);
74+
75+
assertThat(runtimeHints).matches(RuntimeHintsPredicates.proxies().forInterfaces(CrudMethodMetadata.class, //
76+
org.springframework.aop.SpringProxy.class, //
77+
org.springframework.aop.framework.Advised.class, //
78+
org.springframework.core.DecoratingProxy.class));
79+
}
6780
}

0 commit comments

Comments
 (0)