diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java index 878a376029..9a7267b562 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java @@ -16,6 +16,9 @@ package org.springframework.boot; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; import org.springframework.util.ClassUtils; /** @@ -65,4 +68,24 @@ public enum WebApplicationType { return WebApplicationType.SERVLET; } + static class WebApplicationTypeRuntimeHintsRegistrar implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + for (String servletIndicatorClass : SERVLET_INDICATOR_CLASSES) { + registerTypeIfPresent(servletIndicatorClass, classLoader, hints); + } + registerTypeIfPresent(WEBFLUX_INDICATOR_CLASS, classLoader, hints); + registerTypeIfPresent(WEBMVC_INDICATOR_CLASS, classLoader, hints); + } + + private void registerTypeIfPresent(String typeName, ClassLoader classLoader, RuntimeHints hints) { + if (ClassUtils.isPresent(typeName, classLoader)) { + hints.reflection().registerType(TypeReference.of(typeName), (hint) -> { + }); + } + } + + } + } diff --git a/spring-boot-project/spring-boot/src/main/resources/META-INF/spring/aot.factories b/spring-boot-project/spring-boot/src/main/resources/META-INF/spring/aot.factories index eb0fe29494..173e096ecf 100644 --- a/spring-boot-project/spring-boot/src/main/resources/META-INF/spring/aot.factories +++ b/spring-boot-project/spring-boot/src/main/resources/META-INF/spring/aot.factories @@ -1,4 +1,5 @@ org.springframework.aot.hint.RuntimeHintsRegistrar=\ -org.springframework.boot.logging.logback.LogbackRuntimeHintsRegistrar +org.springframework.boot.logging.logback.LogbackRuntimeHintsRegistrar,\ +org.springframework.boot.WebApplicationType.WebApplicationTypeRuntimeHintsRegistrar org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor=\ org.springframework.boot.context.properties.ConfigurationPropertiesBeanFactoryInitializationAotProcessor \ No newline at end of file