Skip to content

Commit 6ba31ac

Browse files
committed
Polish "Add support for Async invocation in a native image"
This registers the hints if the annotation post processor is active, rather than statically. See gh-28710
1 parent 0229cc4 commit 6ba31ac

File tree

3 files changed

+15
-40
lines changed

3 files changed

+15
-40
lines changed

spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@
2525

2626
import org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor;
2727
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
28+
import org.springframework.aot.hint.RuntimeHints;
29+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
30+
import org.springframework.aot.hint.support.RuntimeHintsUtils;
2831
import org.springframework.beans.factory.BeanFactory;
32+
import org.springframework.context.annotation.ImportRuntimeHints;
2933
import org.springframework.core.task.TaskExecutor;
3034
import org.springframework.lang.Nullable;
35+
import org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor.AsyncAnnotationRuntimeHints;
3136
import org.springframework.util.Assert;
3237
import org.springframework.util.function.SingletonSupplier;
3338

@@ -62,6 +67,7 @@
6267
* @see ScheduledAnnotationBeanPostProcessor
6368
*/
6469
@SuppressWarnings("serial")
70+
@ImportRuntimeHints(AsyncAnnotationRuntimeHints.class)
6571
public class AsyncAnnotationBeanPostProcessor extends AbstractBeanFactoryAwareAdvisingPostProcessor {
6672

6773
/**
@@ -154,4 +160,13 @@ public void setBeanFactory(BeanFactory beanFactory) {
154160
this.advisor = advisor;
155161
}
156162

163+
static class AsyncAnnotationRuntimeHints implements RuntimeHintsRegistrar {
164+
165+
@Override
166+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
167+
RuntimeHintsUtils.registerAnnotation(hints, Async.class);
168+
}
169+
170+
}
171+
157172
}

spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingRuntimeHints.java

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
org.springframework.aot.hint.RuntimeHintsRegistrar= \
2-
org.springframework.scheduling.annotation.SchedulingRuntimeHints
3-
41
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor= \
52
org.springframework.context.aot.ReflectiveProcessorBeanRegistrationAotProcessor

0 commit comments

Comments
 (0)