混合Spring AOP和aspectj编译器?

发布于 2024-12-18 06:45:11 字数 355 浏览 2 评论 0原文

我有一个基于 spring 构建的现有项目。

我想捕获对 HibernateTemplate.save() 的调用,因此我在 exec(save()) 上定义了一个切入点,并将时间记录在周围建议中。

我可以使用 spring AOP 定义方面,但我可以看到 spring AOP 仅在切入点中的对象是 bean 时才起作用,但在我的情况下,可以直接在现有客户端代码中的 new() 中创建 HibernateTemplate。

所以我必须通过maven插件使用aspectj编译器。我想知道混合spring AOP和aspectj是否有潜在的冲突? ---- 该项目以前的开发人员可能已经在某处使用过 Spring AOP

谢谢 杨

I have an existing project built on spring.

I would like to catch calls to HibernateTemplate.save() so I define a pointcut on exec(save()), and log the time in an around advice.

I could define the aspects using spring AOP, but I can see the spring AOP only works if the object in the pointcut is a bean, but in my case, the HibernateTemplate could be created in a new() directly in existing client code.

so I have to use aspectj compiler, through maven plugin. I wonder if there are any potential conflicts for mixing spring AOP and aspectj ? ---- previous developers of this project may have already used Spring AOP somewhere

Thanks
Yang

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

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

发布评论

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

评论(2

梦巷 2024-12-25 06:45:11

我通常在所有 Spring 应用程序中使用 AspectJ 而不是 Spring-Proxy-AOP。为此,您需要设置一些 spring 配置,主要设置类似 mode="AspectJ" 的内容。一旦我忘记了其中一些配置,这意味着应用程序对某些方面使用了 AspectJ,对其他方面使用了 Spring-Proxy-AOP,是的,应用程序工作正常(除了我真正需要 AspectJ 而不是 pring-Proxy 的情况) AOP)。

所以从我的角度来看:如果你有足够的测试用例,那就尝试一下。

I normaly use AspectJ instead of Spring-Proxy-AOP for all my Spring Apps. To do this, you need to set some spring configruation, mostly set something like mode="AspectJ". Once I forgot this for some of that configurations, that mean the application used AspectJ for some Aspects and Spring-Proxy-AOP for the others, and yes the application worked correct (except the cases where I really needed AspectJ instead of pring-Proxy-AOP).

So from my point of view: If you have enough test cases, then give them a try.

静待花开 2024-12-25 06:45:11

那会工作得很好。我已经做过很多次了。我总是从 Spring AOP 开始,因为它很简单,并且只有当我需要 Spring AOP 未提供的某些功能时才开始使用 AspectJ。

我唯一的建议是尽可能使用 @AspectJ 样式,这样您就可以轻松地通过较小的配置更改进行更改。

如果您不熟悉注释样式,可以在 Espen Berntsen 的博客 @AspectJ 备忘单

That will work fine. I have done it many times. I always starts with Spring AOP because it is simple and only starts to use AspectJ if I need some functionality not provided by Spring AOP.

My only tips is to use @AspectJ style as much as possible, so you can easily change with minor configuration changes.

If you are new to the annotation style, you can find more information about it on Espen Berntsen's blog, @AspectJ cheat sheet

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