Guard AOT registration of PageModule.

This commit makes sure to only register runtime hints for PageModule if Jackson is present.
Use newly introduced ClassPathExclusions instead of manually creating the ClassLoader.

Closes #3033
Original pull request: #3034
This commit is contained in:
Christoph Strobl
2024-01-24 11:28:23 +01:00
committed by Mark Paluch
parent 36d6a78ded
commit 18386c8b40
7 changed files with 390 additions and 10 deletions

View File

@@ -20,6 +20,7 @@ import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeReference;
import org.springframework.data.web.config.SpringDataJacksonConfiguration.PageModule;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
* {@link RuntimeHintsRegistrar} providing hints for web usage.
@@ -32,7 +33,9 @@ class WebRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
hints.reflection().registerType(TypeReference.of("org.springframework.data.domain.Unpaged"),
hint -> hint.onReachableType(PageModule.class));
if (ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader)) {
hints.reflection().registerType(TypeReference.of("org.springframework.data.domain.Unpaged"),
hint -> hint.onReachableType(PageModule.class));
}
}
}