Register reflection hints for ApplicationProperties
Closes gh-42038
This commit is contained in:
parent
162c929a80
commit
45b83d5d80
|
@ -20,6 +20,7 @@ import java.util.LinkedHashSet;
|
|||
import java.util.Set;
|
||||
|
||||
import org.springframework.boot.Banner.Mode;
|
||||
import org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar;
|
||||
import org.springframework.boot.logging.LoggingSystemProperty;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
|
@ -156,4 +157,12 @@ class ApplicationProperties {
|
|||
this.webApplicationType = webApplicationType;
|
||||
}
|
||||
|
||||
static class ApplicationPropertiesRuntimeHints extends BindableRuntimeHintsRegistrar {
|
||||
|
||||
ApplicationPropertiesRuntimeHints() {
|
||||
super(ApplicationProperties.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
|
|||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.boot.Banner.Mode;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
|
||||
import org.springframework.boot.convert.ApplicationConversionService;
|
||||
|
@ -1594,14 +1593,6 @@ public class SpringApplication {
|
|||
|
||||
}
|
||||
|
||||
static class SpringApplicationRuntimeHints extends BindableRuntimeHintsRegistrar {
|
||||
|
||||
SpringApplicationRuntimeHints() {
|
||||
super(SpringApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception that can be thrown to silently exit a running {@link SpringApplication}
|
||||
* without handling run failures.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
org.springframework.aot.hint.RuntimeHintsRegistrar=\
|
||||
org.springframework.boot.SpringApplication.SpringApplicationRuntimeHints,\
|
||||
org.springframework.boot.ApplicationProperties.ApplicationPropertiesRuntimeHints,\
|
||||
org.springframework.boot.SpringApplicationBannerPrinter.SpringApplicationBannerPrinterRuntimeHints,\
|
||||
org.springframework.boot.WebApplicationType.WebApplicationTypeRuntimeHints,\
|
||||
org.springframework.boot.context.config.ConfigDataLocationRuntimeHints,\
|
||||
|
|
|
@ -18,6 +18,9 @@ package org.springframework.boot;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.ApplicationProperties.ApplicationPropertiesRuntimeHints;
|
||||
import org.springframework.boot.Banner.Mode;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
|
@ -44,4 +47,19 @@ class ApplicationPropertiesTests {
|
|||
assertThat(properties.getBannerMode(environment)).isEqualTo(Mode.OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints hints = new RuntimeHints();
|
||||
new ApplicationPropertiesRuntimeHints().registerHints(hints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(ApplicationProperties.class)).accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "setBannerMode"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "getSources"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "setSources"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "getBannerMode"))
|
||||
.rejects(hints);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,8 +44,6 @@ import org.mockito.Mockito;
|
|||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanCurrentlyInCreationException;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
|
@ -58,7 +56,6 @@ import org.springframework.beans.factory.support.BeanNameGenerator;
|
|||
import org.springframework.beans.factory.support.DefaultBeanNameGenerator;
|
||||
import org.springframework.boot.Banner.Mode;
|
||||
import org.springframework.boot.BootstrapRegistry.InstanceSupplier;
|
||||
import org.springframework.boot.SpringApplication.SpringApplicationRuntimeHints;
|
||||
import org.springframework.boot.availability.AvailabilityChangeEvent;
|
||||
import org.springframework.boot.availability.AvailabilityState;
|
||||
import org.springframework.boot.availability.LivenessState;
|
||||
|
@ -1412,18 +1409,6 @@ class SpringApplicationTests {
|
|||
then(listener).should(never()).onApplicationEvent(any(ApplicationFailedEvent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints hints = new RuntimeHints();
|
||||
new SpringApplicationRuntimeHints().registerHints(hints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(SpringApplication.class)).accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SpringApplication.class, "setBannerMode"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SpringApplication.class, "getSources")).accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SpringApplication.class, "setSources")).accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SpringApplication.class, "load")).rejects(hints);
|
||||
}
|
||||
|
||||
@Test // gh-32555
|
||||
void shouldUseAotInitializer() {
|
||||
SpringApplication application = new SpringApplication(ExampleAotProcessedMainClass.class);
|
||||
|
|
Loading…
Reference in New Issue