From 56a8c1a9db8afa4b7b24dce5801e9d90d7bf7a7d Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 29 Jul 2022 13:23:32 +0200 Subject: [PATCH] Register proxy hint for meta-annotations with attribute override Closes gh-28767 --- .../aot/hint/support/RuntimeHintsUtils.java | 5 ++++- .../aot/hint/support/RuntimeHintsUtilsTests.java | 15 ++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java b/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java index b8eff9c103..a859807883 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java @@ -60,7 +60,10 @@ public abstract class RuntimeHintsUtils { hints.reflection().registerType(annotationType, ANNOTATION_HINT); Set> allAnnotations = new LinkedHashSet<>(); collectAliasedAnnotations(new HashSet<>(), allAnnotations, annotationType); - allAnnotations.forEach(annotation -> hints.reflection().registerType(annotation, ANNOTATION_HINT)); + allAnnotations.forEach(annotation -> { + hints.reflection().registerType(annotation, ANNOTATION_HINT); + hints.proxies().registerJdkProxy(annotation, SynthesizedAnnotation.class); + }); if (!allAnnotations.isEmpty()) { hints.proxies().registerJdkProxy(annotationType, SynthesizedAnnotation.class); } diff --git a/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java b/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java index 5a7464040c..385a2c951b 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java @@ -60,13 +60,15 @@ class RuntimeHintsUtilsTests { } @Test - void registerAnnotationTypeProxyRegistersJdkProxy() { + void registerAnnotationTypeProxyRegistersJdkProxies() { RuntimeHintsUtils.registerAnnotation(this.hints, RetryInvoker.class); assertThat(this.hints.reflection().typeHints()) .anySatisfy(annotationHint(RetryInvoker.class)) .anySatisfy(annotationHint(SampleInvoker.class)); - assertThat(this.hints.proxies().jdkProxies()).singleElement() - .satisfies(annotationProxy(RetryInvoker.class)); + assertThat(this.hints.proxies().jdkProxies()) + .anySatisfy(annotationProxy(RetryInvoker.class)) + .anySatisfy(annotationProxy(SampleInvoker.class)) + .hasSize(2); } @Test @@ -78,8 +80,11 @@ class RuntimeHintsUtilsTests { .anySatisfy(annotationHint(RetryInvoker.class)) .anySatisfy(annotationHint(SampleInvoker.class)) .hasSize(3); - assertThat(this.hints.proxies().jdkProxies()).singleElement() - .satisfies(annotationProxy(RetryWithEnabledFlagInvoker.class)); + assertThat(this.hints.proxies().jdkProxies()) + .anySatisfy(annotationProxy(RetryWithEnabledFlagInvoker.class)) + .anySatisfy(annotationProxy(RetryInvoker.class)) + .anySatisfy(annotationProxy(SampleInvoker.class)) + .hasSize(3); } private Consumer annotationHint(Class type) {