@Override public void setBeanFactory(BeanFactory beanFactory) { super.setBeanFactory(beanFactory); AsyncAnnotationAdvisor advisor = new AsyncAnnotationAdvisor(this.executor, this.exceptionHandler); if (this.asyncAnnotationType != null) { advisor.setAsyncAnnotationType(this.asyncAnnotationType); } advisor.setBeanFactory(beanFactory); this.advisor = advisor; }
/** * Create a new {@code AsyncAnnotationAdvisor} for the given task executor. * @param executor the task executor to use for asynchronous methods * (can be {@code null} to trigger default executor resolution) * @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use to * handle unexpected exception thrown by asynchronous method executions * @since 5.1 * @see AnnotationAsyncExecutionInterceptor#getDefaultExecutor(BeanFactory) */ @SuppressWarnings("unchecked") public AsyncAnnotationAdvisor( @Nullable Supplier<Executor> executor, @Nullable Supplier<AsyncUncaughtExceptionHandler> exceptionHandler) { Set<Class<? extends Annotation>> asyncAnnotationTypes = new LinkedHashSet<>(2); asyncAnnotationTypes.add(Async.class); try { asyncAnnotationTypes.add((Class<? extends Annotation>) ClassUtils.forName("javax.ejb.Asynchronous", AsyncAnnotationAdvisor.class.getClassLoader())); } catch (ClassNotFoundException ex) { // If EJB 3.1 API not present, simply ignore. } this.advice = buildAdvice(executor, exceptionHandler); this.pointcut = buildPointcut(asyncAnnotationTypes); }
@Test public void testMethodValidationInterceptor() { MyValidBean bean = new MyValidBean(); ProxyFactory proxyFactory = new ProxyFactory(bean); proxyFactory.addAdvice(new MethodValidationInterceptor()); proxyFactory.addAdvisor(new AsyncAnnotationAdvisor()); doTestProxyValidation((MyValidInterface) proxyFactory.getProxy()); }
/** * Set the 'async' annotation type. * <p>The default async annotation type is the {@link Async} annotation, as well * as the EJB 3.1 {@code javax.ejb.Asynchronous} annotation (if present). * <p>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. * @param asyncAnnotationType the desired annotation type */ public void setAsyncAnnotationType(Class<? extends Annotation> asyncAnnotationType) { Assert.notNull(asyncAnnotationType, "'asyncAnnotationType' must not be null"); Set<Class<? extends Annotation>> asyncAnnotationTypes = new HashSet<>(); asyncAnnotationTypes.add(asyncAnnotationType); this.pointcut = buildPointcut(asyncAnnotationTypes); }
this.advice = buildAdvice(executor, exceptionHandler); this.pointcut = buildPointcut(asyncAnnotationTypes);
@Test public void testMethodValidationInterceptor() { MyValidBean bean = new MyValidBean(); ProxyFactory proxyFactory = new ProxyFactory(bean); proxyFactory.addAdvice(new MethodValidationInterceptor()); proxyFactory.addAdvisor(new AsyncAnnotationAdvisor()); doTestProxyValidation((MyValidInterface) proxyFactory.getProxy()); }
/** * Set the 'async' annotation type. * <p>The default async annotation type is the {@link Async} annotation, as well * as the EJB 3.1 {@code javax.ejb.Asynchronous} annotation (if present). * <p>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. * @param asyncAnnotationType the desired annotation type */ public void setAsyncAnnotationType(Class<? extends Annotation> asyncAnnotationType) { Assert.notNull(asyncAnnotationType, "'asyncAnnotationType' must not be null"); Set<Class<? extends Annotation>> asyncAnnotationTypes = new HashSet<>(); asyncAnnotationTypes.add(asyncAnnotationType); this.pointcut = buildPointcut(asyncAnnotationTypes); }
@Override public void setBeanFactory(BeanFactory beanFactory) { super.setBeanFactory(beanFactory); AsyncAnnotationAdvisor advisor = new AsyncAnnotationAdvisor(this.executor, this.exceptionHandler); if (this.asyncAnnotationType != null) { advisor.setAsyncAnnotationType(this.asyncAnnotationType); } advisor.setBeanFactory(beanFactory); this.advisor = advisor; }
/** * Create a new {@code AsyncAnnotationAdvisor} for the given task executor. * @param executor the task executor to use for asynchronous methods * (can be {@code null} to trigger default executor resolution) * @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use to * handle unexpected exception thrown by asynchronous method executions * @since 5.1 * @see AnnotationAsyncExecutionInterceptor#getDefaultExecutor(BeanFactory) */ @SuppressWarnings("unchecked") public AsyncAnnotationAdvisor( @Nullable Supplier<Executor> executor, @Nullable Supplier<AsyncUncaughtExceptionHandler> exceptionHandler) { Set<Class<? extends Annotation>> asyncAnnotationTypes = new LinkedHashSet<>(2); asyncAnnotationTypes.add(Async.class); try { asyncAnnotationTypes.add((Class<? extends Annotation>) ClassUtils.forName("javax.ejb.Asynchronous", AsyncAnnotationAdvisor.class.getClassLoader())); } catch (ClassNotFoundException ex) { // If EJB 3.1 API not present, simply ignore. } this.advice = buildAdvice(executor, exceptionHandler); this.pointcut = buildPointcut(asyncAnnotationTypes); }
/** * Set the 'async' annotation type. * <p>The default async annotation type is the {@link Async} annotation, as well * as the EJB 3.1 {@code javax.ejb.Asynchronous} annotation (if present). * <p>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. * @param asyncAnnotationType the desired annotation type */ public void setAsyncAnnotationType(Class<? extends Annotation> asyncAnnotationType) { Assert.notNull(asyncAnnotationType, "'asyncAnnotationType' must not be null"); Set<Class<? extends Annotation>> asyncAnnotationTypes = new HashSet<>(); asyncAnnotationTypes.add(asyncAnnotationType); this.pointcut = buildPointcut(asyncAnnotationTypes); }
@Override public void setBeanFactory(BeanFactory beanFactory) { super.setBeanFactory(beanFactory); AsyncAnnotationAdvisor advisor = new AsyncAnnotationAdvisor(this.executor, this.exceptionHandler); if (this.asyncAnnotationType != null) { advisor.setAsyncAnnotationType(this.asyncAnnotationType); } advisor.setBeanFactory(beanFactory); this.advisor = advisor; }