Adapt to changes in Spring Framework

This commit is contained in:
Stephane Nicoll 2022-08-16 16:02:00 +02:00
parent 12d9864e41
commit 888ccfea2d
4 changed files with 20 additions and 37 deletions

View File

@ -21,11 +21,8 @@ import java.util.stream.Stream;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.support.RuntimeHintsUtils;
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.EndpointExtension;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
/**
* {@link RuntimeHintsRegistrar} for actuator support.
@ -36,10 +33,8 @@ class ActuatorAnnotationsRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
Stream.of(ReadOperation.class, WriteOperation.class, DeleteOperation.class)
.forEach((annotationType) -> RuntimeHintsUtils.registerAnnotation(hints, annotationType));
Stream.of(Endpoint.class, EndpointExtension.class)
.forEach((annotationType) -> RuntimeHintsUtils.registerComposableAnnotation(hints, annotationType));
.forEach((annotationType) -> RuntimeHintsUtils.registerSynthesizedAnnotation(hints, annotationType));
}
}

View File

@ -21,14 +21,10 @@ import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.EndpointExtension;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.core.annotation.SynthesizedAnnotation;
import static org.assertj.core.api.Assertions.assertThat;
@ -50,16 +46,6 @@ class ActuatorAnnotationsRuntimeHintsTests {
this.registrar.registerHints(this.runtimeHints, getClass().getClassLoader());
}
@Test
void shouldRegisterReflectionHints() {
Set<Class<?>> annotations = Set.of(Endpoint.class, ReadOperation.class, WriteOperation.class,
DeleteOperation.class, EndpointExtension.class);
for (Class<?> annotation : annotations) {
assertThat(RuntimeHintsPredicates.reflection().onType(annotation)
.withAnyMemberCategory(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.runtimeHints);
}
}
@Test
void shouldRegisterProxyHints() {
Set<Class<?>> synthesizedAnnotations = Set.of(Endpoint.class, EndpointExtension.class);

View File

@ -67,7 +67,8 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessor implements Be
@Override
public void applyTo(GenerationContext generationContext,
BeanFactoryInitializationCode beanFactoryInitializationCode) {
RuntimeHintsUtils.registerAnnotation(generationContext.getRuntimeHints(), ConfigurationProperties.class);
RuntimeHintsUtils.registerSynthesizedAnnotation(generationContext.getRuntimeHints(),
ConfigurationProperties.class);
for (Class<?> type : this.types) {
ConfigurationPropertiesReflectionHintsProcessor.processConfigurationProperties(type,
generationContext.getRuntimeHints().reflection());

View File

@ -46,6 +46,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.annotation.SynthesizedAnnotation;
import org.springframework.core.env.Environment;
import static org.assertj.core.api.Assertions.assertThat;
@ -86,8 +87,10 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
@Test
void registerConfigurationPropertiesAnnotation() {
RuntimeHints runtimeHints = process(SampleProperties.class);
assertThat(runtimeHints.reflection().getTypeHint(ConfigurationProperties.class)).satisfies(
(hint) -> assertThat(hint.getMemberCategories()).contains(MemberCategory.INVOKE_DECLARED_METHODS));
assertThat(runtimeHints.proxies().jdkProxies()).singleElement()
.satisfies((hint) -> assertThat(hint.getProxiedInterfaces()).containsExactly(
TypeReference.of(ConfigurationProperties.class),
TypeReference.of(SynthesizedAnnotation.class)));
}
@Test
@ -111,7 +114,7 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
List<TypeHint> typeHints = runtimeHints.reflection().typeHints().toList();
assertThat(typeHints).anySatisfy(javaBeanBinding(SamplePropertiesWithMap.class));
assertThat(typeHints).anySatisfy(javaBeanBinding(Address.class));
assertThat(typeHints).hasSize(3);
assertThat(typeHints).hasSize(2);
}
@Test
@ -120,7 +123,7 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
List<TypeHint> typeHints = runtimeHints.reflection().typeHints().toList();
assertThat(typeHints).anySatisfy(javaBeanBinding(SamplePropertiesWithList.class));
assertThat(typeHints).anySatisfy(javaBeanBinding(Address.class));
assertThat(typeHints).hasSize(3);
assertThat(typeHints).hasSize(2);
}
@Test
@ -129,7 +132,7 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
List<TypeHint> typeHints = runtimeHints.reflection().typeHints().toList();
assertThat(typeHints).anySatisfy(javaBeanBinding(SamplePropertiesWithArray.class));
assertThat(typeHints).anySatisfy(javaBeanBinding(Address.class));
assertThat(typeHints).hasSize(3);
assertThat(typeHints).hasSize(2);
}
@Test
@ -137,7 +140,7 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
RuntimeHints runtimeHints = process(SamplePropertiesWithSimpleList.class);
List<TypeHint> typeHints = runtimeHints.reflection().typeHints().toList();
assertThat(typeHints).anySatisfy(javaBeanBinding(SamplePropertiesWithSimpleList.class));
assertThat(typeHints).hasSize(2);
assertThat(typeHints).hasSize(1);
}
@Test
@ -146,7 +149,7 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
List<TypeHint> typeHints = runtimeHints.reflection().typeHints().toList();
assertThat(typeHints).anySatisfy(valueObjectBinding(SampleImmutableProperties.class,
SampleImmutableProperties.class.getDeclaredConstructors()[0]));
assertThat(typeHints).hasSize(2);
assertThat(typeHints).hasSize(1);
}
@Test
@ -155,7 +158,7 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
List<TypeHint> typeHints = runtimeHints.reflection().typeHints().toList();
assertThat(typeHints).anySatisfy(valueObjectBinding(SampleImmutablePropertiesWithSeveralConstructors.class,
SampleImmutablePropertiesWithSeveralConstructors.class.getDeclaredConstructor(String.class)));
assertThat(typeHints).hasSize(2);
assertThat(typeHints).hasSize(1);
}
@Test
@ -166,7 +169,7 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
SampleImmutablePropertiesWithList.class.getDeclaredConstructors()[0]));
assertThat(typeHints).anySatisfy(valueObjectBinding(Person.class, Person.class.getDeclaredConstructors()[0]));
assertThat(typeHints).anySatisfy(valueObjectBinding(Address.class, Address.class.getDeclaredConstructors()[0]));
assertThat(typeHints).hasSize(4);
assertThat(typeHints).hasSize(3);
}
@Test
@ -182,7 +185,7 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
assertThat(runtimeHints.reflection().typeHints())
.anySatisfy(javaBeanBinding(SamplePropertiesWithExternalNested.class))
.anySatisfy(javaBeanBinding(SampleType.class)).anySatisfy(javaBeanBinding(SampleType.Nested.class))
.hasSize(4);
.hasSize(3);
}
@Test
@ -190,7 +193,7 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
RuntimeHints runtimeHints = process(SamplePropertiesWithRecursive.class);
assertThat(runtimeHints.reflection().typeHints())
.anySatisfy(javaBeanBinding(SamplePropertiesWithRecursive.class))
.anySatisfy(javaBeanBinding(Recursive.class)).hasSize(3);
.anySatisfy(javaBeanBinding(Recursive.class)).hasSize(2);
}
@Test
@ -201,16 +204,14 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
SampleImmutablePropertiesWithRecursive.class.getDeclaredConstructors()[0]))
.anySatisfy(valueObjectBinding(ImmutableRecursive.class,
ImmutableRecursive.class.getDeclaredConstructors()[0]))
.hasSize(3);
.hasSize(2);
}
@Test
void processConfigurationPropertiesWithWellKnownTypes() {
RuntimeHints runtimeHints = process(SamplePropertiesWithWellKnownTypes.class);
assertThat(runtimeHints.reflection().typeHints())
.anySatisfy(javaBeanBinding(SamplePropertiesWithWellKnownTypes.class))
// TODO
.hasSize(2);
.anySatisfy(javaBeanBinding(SamplePropertiesWithWellKnownTypes.class)).hasSize(1);
}
@Test
@ -219,7 +220,7 @@ class ConfigurationPropertiesBeanFactoryInitializationAotProcessorTests {
assertThat(runtimeHints.reflection().typeHints())
.anySatisfy(javaBeanBinding(SamplePropertiesWithCrossReference.class))
.anySatisfy(javaBeanBinding(CrossReferenceA.class)).anySatisfy(javaBeanBinding(CrossReferenceB.class))
.hasSize(4);
.hasSize(3);
}
@Test