diff --git a/core/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java b/core/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java index 875cb108880..0f493b49a06 100644 --- a/core/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java +++ b/core/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java @@ -26,6 +26,10 @@ import java.util.List; import java.util.SortedSet; import java.util.concurrent.Future; +import org.jspecify.annotations.Nullable; + +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.util.ClassUtils; /** @@ -96,8 +100,11 @@ public enum JavaVersion { private final boolean available; + private final Class versionSpecificClass; + JavaVersion(String name, Class versionSpecificClass, String versionSpecificMethod, Class... paramTypes) { this.name = name; + this.versionSpecificClass = versionSpecificClass; this.available = ClassUtils.hasMethod(versionSpecificClass, versionSpecificMethod, paramTypes); } @@ -139,4 +146,15 @@ public enum JavaVersion { return compareTo(version) < 0; } + static class Hints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { + for (JavaVersion javaVersion : JavaVersion.values()) { + hints.reflection().registerType(javaVersion.versionSpecificClass); + } + } + + } + } diff --git a/core/spring-boot/src/main/resources/META-INF/spring/aot.factories b/core/spring-boot/src/main/resources/META-INF/spring/aot.factories index 4a0efd5e6c6..56dd9a7032a 100644 --- a/core/spring-boot/src/main/resources/META-INF/spring/aot.factories +++ b/core/spring-boot/src/main/resources/META-INF/spring/aot.factories @@ -10,7 +10,8 @@ org.springframework.boot.logging.log4j2.Log4J2RuntimeHints,\ org.springframework.boot.logging.logback.LogbackRuntimeHints,\ org.springframework.boot.logging.structured.ElasticCommonSchemaProperties$ElasticCommonSchemaPropertiesRuntimeHints,\ org.springframework.boot.logging.structured.GraylogExtendedLogFormatProperties$GraylogExtendedLogFormatPropertiesRuntimeHints,\ -org.springframework.boot.logging.structured.StructuredLoggingJsonProperties$StructuredLoggingJsonPropertiesRuntimeHints +org.springframework.boot.logging.structured.StructuredLoggingJsonProperties$StructuredLoggingJsonPropertiesRuntimeHints,\ +org.springframework.boot.system.JavaVersion$Hints org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor=\ org.springframework.boot.context.properties.ConfigurationPropertiesBeanFactoryInitializationAotProcessor,\