Apply AsyncUncaughtExceptionHandler to AspectJ

Prior to this commit, only @Async annotated methods with proxy style
had their custom uncaught exception handler applied. This commit
harmonizes the configuration so that AspectJ applies that behaviour as
well.

Issue: SPR-12090
This commit is contained in:
Stephane Nicoll
2014-08-18 10:51:07 +02:00
parent 0dba70fe15
commit 8fc191c95e
7 changed files with 219 additions and 59 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ import org.springframework.core.task.AsyncTaskExecutor;
* @author Ramnivas Laddad
* @author Juergen Hoeller
* @author Chris Beams
* @author Stephane Nicoll
* @since 3.0.5
*/
public abstract aspect AbstractAsyncExecutionAspect extends AsyncExecutionAspectSupport {
@@ -42,7 +43,7 @@ public abstract aspect AbstractAsyncExecutionAspect extends AsyncExecutionAspect
/**
* Create an {@code AnnotationAsyncExecutionAspect} with a {@code null} default
* executor, which should instead be set via {@code #aspectOf} and
* {@link #setExecutor(Executor)}.
* {@link #setExecutor(Executor)}. The same applies for {@link #setExceptionHandler}
*/
public AbstractAsyncExecutionAspect() {
super(null);
@@ -56,16 +57,21 @@ public abstract aspect AbstractAsyncExecutionAspect extends AsyncExecutionAspect
* otherwise.
*/
Object around() : asyncMethod() {
MethodSignature methodSignature = (MethodSignature) thisJoinPointStaticPart.getSignature();
final MethodSignature methodSignature = (MethodSignature) thisJoinPointStaticPart.getSignature();
AsyncTaskExecutor executor = determineAsyncExecutor(methodSignature.getMethod());
if (executor == null) {
return proceed();
}
Callable<Object> callable = new Callable<Object>() {
public Object call() throws Exception {
Object result = proceed();
if (result instanceof Future) {
return ((Future<?>) result).get();
try {
Object result = proceed();
if (result instanceof Future) {
return ((Future<?>) result).get();
}
}
catch (Throwable ex) {
handleError(ex, methodSignature.getMethod(), thisJoinPoint.getArgs());
}
return null;
}};

View File

@@ -29,6 +29,7 @@ import org.springframework.scheduling.config.TaskManagementConfigUtils;
* to enable AspectJ-based asynchronous method execution.
*
* @author Chris Beams
* @author Stephane Nicoll
* @since 3.1
* @see EnableAsync
* @see org.springframework.scheduling.annotation.AsyncConfigurationSelector
@@ -44,6 +45,9 @@ public class AspectJAsyncConfiguration extends AbstractAsyncConfiguration {
if (this.executor != null) {
asyncAspect.setExecutor(this.executor);
}
if (this.exceptionHandler != null) {
asyncAspect.setExceptionHandler(this.exceptionHandler);
}
return asyncAspect;
}