使用AspectJ的异步执行方面 [英] Asynchronous execution aspect using AspectJ

查看:92
本文介绍了使用AspectJ的异步执行方面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题所在-

我正在使用Spring提供的@Async异步执行一些方法.但是,由于它是基于代理的,因此,如果从同一类中调用该方法,则将无法正常工作. 我确实需要在同一类中调用异步方法.

I was using @Async provided by Spring to execute some methods asynchronously. However, because it is proxy based, it wouldn't work if the method is called from within the same class. I do need my async methods to be called from within the same class.

我知道如果我使用AspectJ而不是Spring AOP,我将能够做到这一点.

I know if I use AspectJ instead of Spring AOP, I will be able to do that.

所以我的问题是,有没有一种方法可以使用Spring的@Async并加载时间进行编织? 还是已经编写了一个我可以使用的基于AspectJ的异步执行方面,而不是自己编写?

So my question is, is there a way to use Spring's @Async and load time weave it? Or, is there an AspectJ based async execution aspect already written that I can use, instead of writing my own?

推荐答案

是的,用@Async注释具体类的方法,将spring-aspects JAR(包含异步方面)放入您的类路径中,使用<task:annotation-driven mode="aspectj" />在您的Spring配置中,并应用编译时或加载时编织,将spring-aspects用作方面库.

Yes, annotate a concrete class' method with @Async, put spring-aspects JAR (which contains the async aspect) into your classpath, use <task:annotation-driven mode="aspectj" /> in your Spring config and apply either compile-time or load-time weaving, referencing spring-aspects as an aspect library.

这篇关于使用AspectJ的异步执行方面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆