How to intercept static methods in Spring?

后端 未结 2 1226
北荒
北荒 2020-12-06 11:01

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

相关标签:
2条回答
  • 2020-12-06 11:17

    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/

    0 讨论(0)
  • 2020-12-06 11:33

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

    Taken from the blog post comment from LIMC's answer

    0 讨论(0)
提交回复
热议问题