Allow WebApplicationType to be deduced in a native image
Closes gh-31217
This commit is contained in:
parent
44a8e91b9e
commit
5f54289e97
|
@ -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) -> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue