开发者

How to intercept static methods in Spring?

开发者 https://www.devze.com 2023-02-11 12:02 出处:网络
Subject line basically says it a开发者_开发知识库ll. 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

Subject line basically says it a开发者_开发知识库ll. 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.


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/


See PowerMock https://github.com/powermock/powermock it can mock static methods

Taken from the blog post comment from LIMC's answer

0

精彩评论

暂无评论...
验证码 换一张
取 消