BeanFactoryAnnotationUtils throws NoSuchBeanDefinitionExceptions instead of IllegalStateExceptions

Issue: SPR-9652
This commit is contained in:
Juergen Hoeller
2012-09-10 15:26:43 +02:00
parent 7d8843d069
commit 430db261e7
2 changed files with 35 additions and 41 deletions

View File

@@ -17,7 +17,6 @@
package org.springframework.aop.interceptor;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
@@ -85,6 +84,32 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
this.beanFactory = beanFactory;
}
/**
* Determine the specific executor to use when executing the given method.
* @returns the executor to use (never {@code null})
*/
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
if (!this.executors.containsKey(method)) {
Executor executor = this.defaultExecutor;
String qualifier = getExecutorQualifier(method);
if (StringUtils.hasLength(qualifier)) {
Assert.notNull(this.beanFactory,
"BeanFactory must be set on " + this.getClass().getSimpleName() +
" to access qualified executor [" + qualifier + "]");
executor = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, Executor.class, qualifier);
}
if (executor instanceof AsyncTaskExecutor) {
this.executors.put(method, (AsyncTaskExecutor) executor);
}
else if (executor != null) {
this.executors.put(method, new TaskExecutorAdapter(executor));
}
}
return this.executors.get(method);
}
/**
* Return the qualifier or bean name of the executor to be used when executing the
* given async method, typically specified in the form of an annotation attribute.
@@ -97,32 +122,4 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
*/
protected abstract String getExecutorQualifier(Method method);
/**
* Determine the specific executor to use when executing the given method.
* @returns the executor to use (never {@code null})
*/
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
if (!this.executors.containsKey(method)) {
Executor executor = this.defaultExecutor;
String qualifier = getExecutorQualifier(method);
if (StringUtils.hasLength(qualifier)) {
Assert.notNull(this.beanFactory,
"BeanFactory must be set on " + this.getClass().getSimpleName() +
" to access qualified executor [" + qualifier + "]");
executor = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, Executor.class, qualifier);
}
if (executor instanceof AsyncTaskExecutor) {
this.executors.put(method, (AsyncTaskExecutor) executor);
}
else if (executor instanceof Executor) {
this.executors.put(method, new TaskExecutorAdapter(executor));
}
}
return this.executors.get(method);
}
}