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

查看:71
本文介绍了使用 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(其中包含异步方面)到您的类路径中,在您的 Spring 配置中使用 <task:annotation-driven mode="aspectj"/> 并应用编译时或加载时编织,引用 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天全站免登陆