Class AsyncAnnotationBeanPostProcessor
- java.lang.Object
- org.springframework.aop.framework.ProxyConfig
- org.springframework.aop.framework.ProxyProcessorSupport
- org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor
- org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor
- org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor
- All Implemented Interfaces:
Serializable
,AopInfrastructureBean
,Aware
,BeanClassLoaderAware
,BeanFactoryAware
,BeanPostProcessor
,Ordered
public class AsyncAnnotationBeanPostProcessor extends AbstractBeanFactoryAwareAdvisingPostProcessor
Bean post-processor that automatically applies asynchronous invocation behavior to any bean that carries theAsync
annotation at class or method-level by adding a correspondingAsyncAnnotationAdvisor
to the exposed proxy (either an existing AOP proxy or a newly generated proxy that implements all of the target's interfaces).The
TaskExecutor
responsible for the asynchronous execution may be provided as well as the annotation type that indicates a method should be invoked asynchronously. If no annotation type is specified, this post- processor will detect both Spring's@Async
annotation as well as the EJB 3.1javax.ejb.Asynchronous
annotation.For methods having a
void
return type, any exception thrown during the asynchronous method invocation cannot be accessed by the caller. AnAsyncUncaughtExceptionHandler
can be specified to handle these cases.Note: The underlying async advisor applies before existing advisors by default, in order to switch to async execution as early as possible in the invocation chain.
- Since:
- 3.0
- Author:
- Mark Fisher, Juergen Hoeller, Stephane Nicoll
- See Also:
Async
,AsyncAnnotationAdvisor
,AbstractAdvisingBeanPostProcessor.setBeforeExistingAdvisors(boolean)
,ScheduledAnnotationBeanPostProcessor
, Serialized Form
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_TASK_EXECUTOR_BEAN_NAME
The default name of theTaskExecutor
bean to pick up: "taskExecutor".protected Log
logger
Fields inherited from class org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor
advisor, beforeExistingAdvisors
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description AsyncAnnotationBeanPostProcessor()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
setAsyncAnnotationType(Class<? extends Annotation> asyncAnnotationType)
Set the 'async' annotation type to be detected at either class or method level.void
setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance.void
setExceptionHandler(AsyncUncaughtExceptionHandler exceptionHandler)
Set theAsyncUncaughtExceptionHandler
to use to handle uncaught exceptions thrown by asynchronous method executions.void
setExecutor(Executor executor)
Set theExecutor
to use when invoking methods asynchronously.Methods inherited from class org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor
prepareProxyFactory
Methods inherited from class org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor
customizeProxyFactory, isEligible, isEligible, postProcessAfterInitialization, postProcessBeforeInitialization, setBeforeExistingAdvisors
Methods inherited from class org.springframework.aop.framework.ProxyProcessorSupport
evaluateProxyInterfaces, getOrder, getProxyClassLoader, isConfigurationCallbackInterface, isInternalLanguageInterface, setBeanClassLoader, setOrder, setProxyClassLoader
Methods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass, toString
Field Detail
DEFAULT_TASK_EXECUTOR_BEAN_NAME
public static final String DEFAULT_TASK_EXECUTOR_BEAN_NAME
The default name of theTaskExecutor
bean to pick up: "taskExecutor".Note that the initial lookup happens by type; this is just the fallback in case of multiple executor beans found in the context.
- Since:
- 4.2
- See Also:
AsyncExecutionAspectSupport.DEFAULT_TASK_EXECUTOR_BEAN_NAME
, Constant Field Values
Constructor Detail
AsyncAnnotationBeanPostProcessor
public AsyncAnnotationBeanPostProcessor()
Method Detail
setAsyncAnnotationType
public void setAsyncAnnotationType(Class<? extends Annotation> asyncAnnotationType)
Set the 'async' annotation type to be detected at either class or method level. By default, both theAsync
annotation and the EJB 3.1javax.ejb.Asynchronous
annotation will be detected.This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate that a method (or all methods of a given class) should be invoked asynchronously.
- Parameters:
asyncAnnotationType
- the desired annotation type
setExecutor
public void setExecutor(Executor executor)
Set theExecutor
to use when invoking methods asynchronously.If not specified, default executor resolution will apply: searching for a unique
TaskExecutor
bean in the context, or for anExecutor
bean named "taskExecutor" otherwise. If neither of the two is resolvable, a local default executor will be created within the interceptor.
setExceptionHandler
public void setExceptionHandler(AsyncUncaughtExceptionHandler exceptionHandler)
Set theAsyncUncaughtExceptionHandler
to use to handle uncaught exceptions thrown by asynchronous method executions.- Since:
- 4.1
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
Description copied from interface:BeanFactoryAware
Callback that supplies the owning factory to a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method.- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Overrides:
setBeanFactory
in classAbstractBeanFactoryAwareAdvisingPostProcessor
- Parameters:
beanFactory
- owning BeanFactory (nevernull
). The bean can immediately call methods on the factory.- See Also:
BeanInitializationException