Class AsyncAnnotationAdvisor
java.lang.Object
org.springframework.aop.support.AbstractPointcutAdvisor
org.springframework.scheduling.annotation.AsyncAnnotationAdvisor
- All Implemented Interfaces:
Serializable,org.springframework.aop.Advisor,org.springframework.aop.PointcutAdvisor,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.core.Ordered
public class AsyncAnnotationAdvisor
extends org.springframework.aop.support.AbstractPointcutAdvisor
implements org.springframework.beans.factory.BeanFactoryAware
Advisor that activates asynchronous method execution through the
Async
annotation. This annotation can be used at the method and type level in
implementation classes as well as in service interfaces.
This advisor detects the EJB 3.1 jakarta.ejb.Asynchronous
annotation as well, treating it exactly like Spring's own Async.
Furthermore, a custom async annotation type may get specified through the
"asyncAnnotationType" property.
- Since:
- 3.0
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.aop.Advisor
EMPTY_ADVICEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionCreate a newAsyncAnnotationAdvisorfor bean-style configuration.AsyncAnnotationAdvisor(Executor executor, org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler exceptionHandler) Create a newAsyncAnnotationAdvisorfor the given task executor.AsyncAnnotationAdvisor(Supplier<Executor> executor, Supplier<org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler> exceptionHandler) Create a newAsyncAnnotationAdvisorfor the given task executor. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.aopalliance.aop.AdvicebuildAdvice(Supplier<Executor> executor, Supplier<org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler> exceptionHandler) protected org.springframework.aop.PointcutbuildPointcut(Set<Class<? extends Annotation>> asyncAnnotationTypes) Calculate a pointcut for the given async annotation types, if any.org.aopalliance.aop.Adviceorg.springframework.aop.PointcutvoidsetAsyncAnnotationType(Class<? extends Annotation> asyncAnnotationType) Set the 'async' annotation type.voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) Set theBeanFactoryto be used when looking up executors by qualifier.Methods inherited from class org.springframework.aop.support.AbstractPointcutAdvisor
equals, getOrder, hashCode, setOrderMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.aop.Advisor
isPerInstance
-
Constructor Details
-
AsyncAnnotationAdvisor
public AsyncAnnotationAdvisor()Create a newAsyncAnnotationAdvisorfor bean-style configuration. -
AsyncAnnotationAdvisor
public AsyncAnnotationAdvisor(@Nullable Executor executor, @Nullable org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler exceptionHandler) Create a newAsyncAnnotationAdvisorfor the given task executor.- Parameters:
executor- the task executor to use for asynchronous methods (can benullto trigger default executor resolution)exceptionHandler- theAsyncUncaughtExceptionHandlerto use to handle unexpected exception thrown by asynchronous method executions- See Also:
-
AsyncExecutionInterceptor.getDefaultExecutor(BeanFactory)
-
AsyncAnnotationAdvisor
public AsyncAnnotationAdvisor(@Nullable Supplier<Executor> executor, @Nullable Supplier<org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler> exceptionHandler) Create a newAsyncAnnotationAdvisorfor the given task executor.- Parameters:
executor- the task executor to use for asynchronous methods (can benullto trigger default executor resolution)exceptionHandler- theAsyncUncaughtExceptionHandlerto use to handle unexpected exception thrown by asynchronous method executions- Since:
- 5.1
- See Also:
-
AsyncExecutionInterceptor.getDefaultExecutor(BeanFactory)
-
-
Method Details
-
setAsyncAnnotationType
Set the 'async' annotation type.The default async annotation type is the
Asyncannotation, as well as the EJB 3.1jakarta.ejb.Asynchronousannotation (if present).This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate that a method is to be executed asynchronously.
- Parameters:
asyncAnnotationType- the desired annotation type
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) Set theBeanFactoryto be used when looking up executors by qualifier.- Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware
-
getAdvice
public org.aopalliance.aop.Advice getAdvice()- Specified by:
getAdvicein interfaceorg.springframework.aop.Advisor
-
getPointcut
public org.springframework.aop.Pointcut getPointcut()- Specified by:
getPointcutin interfaceorg.springframework.aop.PointcutAdvisor
-
buildAdvice
-
buildPointcut
protected org.springframework.aop.Pointcut buildPointcut(Set<Class<? extends Annotation>> asyncAnnotationTypes) Calculate a pointcut for the given async annotation types, if any.- Parameters:
asyncAnnotationTypes- the async annotation types to introspect- Returns:
- the applicable Pointcut object, or
nullif none
-