How to intercept static methods in Spring?

The topic basically says it all. I have a static method that I want to intercept so that advice can be applied to it. I can get this to work with any non-static methods, but I'm not sure how to allow static methods to be intercepted.

+11
source share
2 answers

You cannot do this with Spring AOP because it is proxy based. You must use AspectJ. Take a look at this simple example: http://blog.jayway.com/2007/02/16/static-mock-using-aspectj/

+20
source

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

Taken from the blog, comment from LIMC answer

0
source

All Articles