diff --git a/src/main/java/org/springframework/data/web/aot/WebRuntimeHints.java b/src/main/java/org/springframework/data/web/aot/WebRuntimeHints.java index 3a9aee614..68f01f452 100644 --- a/src/main/java/org/springframework/data/web/aot/WebRuntimeHints.java +++ b/src/main/java/org/springframework/data/web/aot/WebRuntimeHints.java @@ -20,6 +20,7 @@ import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; import org.springframework.data.web.PagedModel; +import org.springframework.data.web.config.EnableSpringDataWebSupport; import org.springframework.data.web.config.SpringDataJacksonConfiguration.PageModule; import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; @@ -35,12 +36,17 @@ class WebRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { + hints.reflection().registerType(org.springframework.data.web.config.SpringDataWebSettings.class, hint -> hint + .withMembers(MemberCategory.INVOKE_DECLARED_METHODS).onReachableType(EnableSpringDataWebSupport.class)); + if (ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader)) { // Page Model for Jackson Rendering hints.reflection().registerType(org.springframework.data.web.PagedModel.class, MemberCategory.INVOKE_PUBLIC_METHODS); - hints.reflection().registerType(PagedModel.PageMetadata.class, MemberCategory.INVOKE_PUBLIC_METHODS); + + hints.reflection().registerType(PagedModel.PageMetadata.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_METHODS); // Type that might not be seen otherwise hints.reflection().registerType(TypeReference.of("org.springframework.data.domain.Unpaged"), diff --git a/src/test/java/org/springframework/data/web/aot/WebRuntimeHintsUnitTests.java b/src/test/java/org/springframework/data/web/aot/WebRuntimeHintsUnitTests.java index 72b20118f..6a88781b5 100644 --- a/src/test/java/org/springframework/data/web/aot/WebRuntimeHintsUnitTests.java +++ b/src/test/java/org/springframework/data/web/aot/WebRuntimeHintsUnitTests.java @@ -15,11 +15,11 @@ */ package org.springframework.data.web.aot; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import org.junit.jupiter.api.Test; - import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.TypeReference; @@ -46,7 +46,7 @@ class WebRuntimeHintsUnitTests { RuntimeHintsPredicates.reflection().onType(TypeReference.of("org.springframework.data.domain.Unpaged"))); } - @Test // GH-3033 + @Test // GH-3033, GH-3171 @ClassPathExclusions(packages = { "com.fasterxml.jackson.databind" }) void shouldRegisterRuntimeHintWithTypeNameWhenJacksonNotPresent() { @@ -56,6 +56,7 @@ class WebRuntimeHintsUnitTests { new WebRuntimeHints().registerHints(runtimeHints, this.getClass().getClassLoader()); - assertThat(runtimeHints.reflection().typeHints()).isEmpty(); + assertThat(runtimeHints).matches(RuntimeHintsPredicates.reflection() + .onType(TypeReference.of("org.springframework.data.web.config.SpringDataWebSettings"))); } }