如何在类上创建一个方面,而不是使用Spring AOP的bean? [英] How to create an aspect on class, that is not a bean using Spring AOP?

查看:269
本文介绍了如何在类上创建一个方面,而不是使用Spring AOP的bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Spring AOP(即ProxyFactoryBean)的旧版应用程序上工作.

I work on an legacy application, where Spring AOP (namely ProxyFactoryBean) is used.

我需要围绕某个类的方法添加一个方面.但是,此类不是不是 bean. AspecjJ切入点表达式将如下所示: execution(* xyz.package.Class.method())

I need to add an aspect around a method of a certain class. This class is not a bean however. The AspecjJ pointcut expression would be like this: execution(* xyz.package.Class.method())

我创建了MethodInterceptorAspectJExpressionPointcut,但是我不知道如何使两者一起工作.

I created a MethodInterceptor and AspectJExpressionPointcut, but I don't know how make those two work together.

编辑:
我没有此类的源代码,它是一个3rd party库.此类的实例不是由我创建的,无论是在源代码中,还是在Spring配置中都没有作为bean.库内部使用它.

EDIT:
I do not have source code for this class, it is a 3rd party library. The instances of this class are not created by me, neither in source code, nor in spring configuration as beans. It is used internally by the library.

任何帮助表示赞赏.

推荐答案

您可以按照

You can use load-time weaving with full AspectJ support as described here, it doesn't require access to the source of classes being advised nor control over their instantiation (though it requires <context:load-time-weaver /> and presence of the weaver itself using -javaagent:... or other methods).

这篇关于如何在类上创建一个方面,而不是使用Spring AOP的bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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