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

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

问题描述

我在使用 Spring AOP(即 ProxyFactoryBean)的遗留应用程序工作.

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

我需要围绕某个类的方法添加一个方面.然而,这个类不是一个bean.AspecjJ 切入点表达式如下所示:<代码>执行(* 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 方库.这个类的实例不是我自己创建的,既不是在源代码中,也不是在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.

感谢任何帮助.

推荐答案

您可以使用具有完整 AspectJ 支持的加载时编织,如这里,它不需要访问被建议的类的源或控制它们的实例化(尽管它需要 <context:load-time-weaver/> 和使用 -javaagent:...其他方法).

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天全站免登陆