I am using Spring’s AOPContext.currentProxy() in a @service class implementation. However, i am using it in a static method and I do something like
public static void addCustomer() {
//....
((CustomerService) AopContext.currentProxy()).addCustomer();
//...
However, I am getting the error — “cannot find proxy” set expose-proxy to true.
Is using static method the reason for this kind of error?
Note: “addCustomer” method is also static
Thanks in advance.
I’m not sure what you are trying to do, but you cannot do it this way at all.
Invocations of
staticmethods are resolved at compile time, therefore they cannot be affected by proxy-based AOP. In other words:AopContext.currentProxy()inside a static method doesn’t make sense (unless you want to get a proxy for enclosing call of some instance method), because invocation of static method is not proxiedAopContext.currentProxy()doesn’t make sense, because it’s resolved at compile time using a static type of expression, i.e. it compiles intoCustomerService.addCustomer().