From 26cec61f3209e487cc2ff6deb6a2e571804267a8 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 12 Sep 2022 14:48:46 +0200 Subject: [PATCH] Adapt to API change in Spring Framework See https://github.com/spring-projects/spring-framework/issues/29135 --- .../metrics/cache/HazelcastCacheMeterBinderProvider.java | 4 +++- .../main/java/org/springframework/boot/AotProcessor.java | 5 +++-- .../ConfigurationPropertiesReflectionHintsProcessor.java | 4 ++-- .../boot/web/client/RestTemplateBuilder.java | 8 +++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/HazelcastCacheMeterBinderProvider.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/HazelcastCacheMeterBinderProvider.java index 56535904d6f..a6ffd9413cc 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/HazelcastCacheMeterBinderProvider.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/HazelcastCacheMeterBinderProvider.java @@ -24,6 +24,7 @@ import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.binder.MeterBinder; import io.micrometer.core.instrument.binder.cache.HazelcastCacheMetrics; +import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.boot.actuate.metrics.cache.HazelcastCacheMeterBinderProvider.HazelcastCacheMeterBinderProviderRuntimeHints; @@ -71,7 +72,8 @@ public class HazelcastCacheMeterBinderProvider implements CacheMeterBinderProvid Method getNativeCacheMethod = ReflectionUtils.findMethod(HazelcastCache.class, "getNativeCache"); Assert.state(getNativeCacheMethod != null, "Unable to find 'getNativeCache' method"); Constructor constructor = HazelcastCacheMetrics.class.getConstructor(Object.class, Iterable.class); - hints.reflection().registerMethod(getNativeCacheMethod).registerConstructor(constructor); + hints.reflection().registerMethod(getNativeCacheMethod, ExecutableMode.INVOKE) + .registerConstructor(constructor, ExecutableMode.INVOKE); } catch (NoSuchMethodException ex) { throw new IllegalStateException(ex); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java index 5fc4a720b4a..c7b9b46fdc1 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java @@ -30,6 +30,7 @@ import org.springframework.aot.generate.ClassNameGenerator; import org.springframework.aot.generate.DefaultGenerationContext; import org.springframework.aot.generate.FileSystemGeneratedFiles; import org.springframework.aot.generate.GeneratedFiles.Kind; +import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.TypeReference; @@ -154,8 +155,8 @@ public class AotProcessor { TypeReference applicationType = TypeReference.of(this.application); ReflectionHints reflection = generationContext.getRuntimeHints().reflection(); reflection.registerType(applicationType); - reflection.registerType(generatedType, - (typeHint) -> typeHint.onReachableType(applicationType).withConstructor(Collections.emptyList())); + reflection.registerType(generatedType, (typeHint) -> typeHint.onReachableType(applicationType) + .withConstructor(Collections.emptyList(), ExecutableMode.INVOKE)); } private Path getRoot(Kind kind) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesReflectionHintsProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesReflectionHintsProcessor.java index 507647224f7..801350984a4 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesReflectionHintsProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesReflectionHintsProcessor.java @@ -107,11 +107,11 @@ public final class ConfigurationPropertiesReflectionHintsProcessor { private void handleConstructor(ReflectionHints reflectionHints) { if (this.bindConstructor != null) { - reflectionHints.registerConstructor(this.bindConstructor); + reflectionHints.registerConstructor(this.bindConstructor, ExecutableMode.INVOKE); return; } Arrays.stream(this.type.getDeclaredConstructors()).filter(this::hasNoParameters).findFirst() - .ifPresent(reflectionHints::registerConstructor); + .ifPresent((constructor) -> reflectionHints.registerConstructor(constructor, ExecutableMode.INVOKE)); } private boolean hasNoParameters(Constructor candidate) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java index 829bd7a718e..f5263583c37 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java @@ -36,6 +36,7 @@ import java.util.function.Supplier; import reactor.netty.http.client.HttpClientRequest; +import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; @@ -803,9 +804,10 @@ public class RestTemplateBuilder { ReflectionUtils.findField(AbstractClientHttpRequestFactoryWrapper.class, "requestFactory"))); ClientHttpRequestFactorySupplier.ClientHttpRequestFactorySupplierRuntimeHints.registerHints(hints, classLoader, (hint) -> { - hint.withMethod("setConnectTimeout", TypeReference.listOf(int.class)); - hint.withMethod("setReadTimeout", TypeReference.listOf(int.class)); - hint.withMethod("setBufferRequestBody", TypeReference.listOf(boolean.class)); + hint.withMethod("setConnectTimeout", TypeReference.listOf(int.class), ExecutableMode.INVOKE); + hint.withMethod("setReadTimeout", TypeReference.listOf(int.class), ExecutableMode.INVOKE); + hint.withMethod("setBufferRequestBody", TypeReference.listOf(boolean.class), + ExecutableMode.INVOKE); }); }