如何使用 Spring AOP 在类上创建一个方面,而不是一个 bean?

发布于 2024-08-25 19:20:22 字数 415 浏览 3 评论 0原文

我正在开发一个遗留应用程序,其中使用了 Spring AOP(即 ProxyFactoryBean )。

我需要围绕某个类的方法添加一个方面。然而,这个类不是 bean。 AspecjJ 切入点表达式如下所示: <代码> 执行(* xyz.package.Class.method())

我创建了一个 MethodInterceptorAspectJExpressionPointcut,但我不知道如何让这两个一起工作。

编辑
我没有这个类的源代码,它是一个第三方库。这个类的实例不是我创建的,无论是在源代码中,还是在 spring 配置中作为 bean 。它由图书馆内部使用。

任何帮助表示赞赏。

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

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())

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

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.

Any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

此刻的回忆 2024-09-01 19:20:22

您可以使用具有完整 AspectJ 支持的加载时编织,如下所述 此处,它不需要访问所建议的类的源代码,也不需要控制它们的实例化(尽管它需要 以及使用 -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).

彼岸花ソ最美的依靠 2024-09-01 19:20:22

尝试@Configurable。 本文档对此进行了解释。

@Configurable 注解将类标记为符合 Spring 驱动配置的条件

(您需要

更新
您可以通过在 applicationContext.xml 中将第 3 方组件列为 (您不需要 <代码>@Configurable 与此)

Try @Configurable. It is explained in this docs.

The @Configurable annotation marks a class as eligible for Spring-driven configuration

(you'd need <context:load-time-weaver />)

Update
You can make a 3rd party component a bean by listing it in applicationContext.xml as <bean class=".." /> (you don't need @Configurable with that)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文