From 3562cd759b6a14981b59c06a7699781b2b570561 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 24 Jul 2013 15:30:18 +0200 Subject: [PATCH] Moved executor null check to AsyncExecutionInterceptor, allowing AbstractAsyncExecutionAspect to fall back to sync execution (as in 3.2.1) Issue: SPR-10636 (cherry picked from commit b6c54c3) --- .../aop/interceptor/AsyncExecutionAspectSupport.java | 5 ++--- .../aop/interceptor/AsyncExecutionInterceptor.java | 8 +++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java index 7fbfbf5604..7cf91ab7e6 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java @@ -87,7 +87,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { /** * Determine the specific executor to use when executing the given method. - * @return the executor to use (never {@code null}) + * @return the executor to use (or {@code null}, but just if no default executor has been set) */ protected AsyncTaskExecutor determineAsyncExecutor(Method method) { AsyncTaskExecutor executor = this.executors.get(method); @@ -101,8 +101,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { this.beanFactory, Executor.class, qualifier); } else if (executorToUse == null) { - throw new IllegalStateException("No executor qualifier specified and no default executor set on " + - getClass().getSimpleName() + " either"); + return null; } executor = (executorToUse instanceof AsyncTaskExecutor ? (AsyncTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse)); diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java index daa23a3293..b521969104 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java @@ -82,7 +82,13 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass); specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); - Future result = determineAsyncExecutor(specificMethod).submit( + AsyncTaskExecutor executor = determineAsyncExecutor(specificMethod); + if (executor == null) { + throw new IllegalStateException( + "No executor specified and no default executor set on AsyncExecutionInterceptor either"); + } + + Future result = executor.submit( new Callable() { public Object call() throws Exception { try {