如何拦截Spring中的静态方法? [英] How to intercept static methods in Spring?

查看:29
本文介绍了如何拦截Spring中的静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主题行基本上说明了一切.我有一个我想拦截的静态方法,以便可以将周围的建议应用于它.我可以让它与任何非静态方法一起使用,但我不确定如何允许拦截静态方法.

Subject line basically says it all. I have a static method I want to intercept so that around advice can be applied to it. I can get this to work with any non-static methods but I'm unsure how to allow static methods to be intercepted.

推荐答案

你不能用 Spring AOP 做到这一点,因为它是基于代理的.您必须使用 AspectJ.看看这个简单的例子:http://blog.jayway.com/2007/02/16/static-mock-using-aspectj/

You can't do that with Spring AOP, because it is proxy based. You have to use AspectJ. Take a look at this simple example: http://blog.jayway.com/2007/02/16/static-mock-using-aspectj/

这篇关于如何拦截Spring中的静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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