Browse Source

Add AOT proxy hints for CrudMethodMetadata.

Closes: #4534
pull/4541/head
Christoph Strobl 2 years ago
parent
commit
645baab77e
No known key found for this signature in database
GPG Key ID: 8CC1AB53391458C8
  1. 15
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/RepositoryRuntimeHints.java
  2. 13
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/aot/RepositoryRuntimeHintsUnitTests.java

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

@ -24,10 +24,12 @@ import org.springframework.aot.hint.RuntimeHints; @@ -24,10 +24,12 @@ import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeReference;
import org.springframework.data.mongodb.aot.MongoAotPredicates;
import org.springframework.data.mongodb.repository.support.CrudMethodMetadata;
import org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor;
import org.springframework.data.mongodb.repository.support.ReactiveQuerydslMongoPredicateExecutor;
import org.springframework.data.querydsl.QuerydslUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
* @author Christoph Strobl
@ -43,6 +45,15 @@ class RepositoryRuntimeHints implements RuntimeHintsRegistrar { @@ -43,6 +45,15 @@ class RepositoryRuntimeHints implements RuntimeHintsRegistrar {
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
MemberCategory.INVOKE_PUBLIC_METHODS));
if (isAopPresent(classLoader)) {
// required for pushing ReadPreference,... into the default repository implementation
hints.proxies().registerJdkProxy(CrudMethodMetadata.class, //
org.springframework.aop.SpringProxy.class, //
org.springframework.aop.framework.Advised.class, //
org.springframework.core.DecoratingProxy.class);
}
if (isReactorPresent()) {
hints.reflection().registerTypes(
@ -77,4 +88,8 @@ class RepositoryRuntimeHints implements RuntimeHintsRegistrar { @@ -77,4 +88,8 @@ class RepositoryRuntimeHints implements RuntimeHintsRegistrar {
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
}
}
private static boolean isAopPresent(@Nullable ClassLoader classLoader) {
return ClassUtils.isPresent("org.springframework.aop.Pointcut", classLoader);
}
}

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

@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test; @@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.data.mongodb.classloading.HidingClassLoader;
import org.springframework.data.mongodb.repository.support.CrudMethodMetadata;
import org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor;
import org.springframework.data.mongodb.repository.support.ReactiveQuerydslMongoPredicateExecutor;
@ -64,4 +65,16 @@ class RepositoryRuntimeHintsUnitTests { @@ -64,4 +65,16 @@ class RepositoryRuntimeHintsUnitTests {
assertThat(runtimeHints).matches(RuntimeHintsPredicates.reflection().onType(QuerydslMongoPredicateExecutor.class)
.and(RuntimeHintsPredicates.reflection().onType(ReactiveQuerydslMongoPredicateExecutor.class).negate()));
}
@Test // GH-2971, GH-4534
void registersProxyForCrudMethodMetadata() {
RuntimeHints runtimeHints = new RuntimeHints();
new RepositoryRuntimeHints().registerHints(runtimeHints, null);
assertThat(runtimeHints).matches(RuntimeHintsPredicates.proxies().forInterfaces(CrudMethodMetadata.class, //
org.springframework.aop.SpringProxy.class, //
org.springframework.aop.framework.Advised.class, //
org.springframework.core.DecoratingProxy.class));
}
}

Loading…
Cancel
Save