开发者

Need help creating a specific pointcut inside of a method

开发者 https://www.devze.com 2023-02-05 23:06 出处:网络
I started with an original question on Need help creating a specific pointcut that utilizes a value from a method annotation

I started with an original question on Need help creating a specific pointcut that utilizes a value from a method annotation

I decided I wanted to ask another question to change the approach I was taking. I have a method (navigation), that has a call inside of that method to another method which I would like to have @Around advice.

@RequestMapping(method = RequestMethod.GET)
public String navigation(ModelMap model) {
    ...        
            // Call Auto Handling
            logger.info("Call AutoHandling");
            this.processAutoHandling(callSession, FunctionalArea.PRE_MAIN_MENU);
        }
        ...

    return forward(returnView);
}

Is this possible as I cannot seem to get this to work if the method is inside of the same class.

This work if it was not on the object itself:

@Around("execution(* *.processAutoHandling(..)) &&" +
        "args(callSession, functionalArea) && " +
        "args(functionalArea) && " +
        "target(bean)"
)
public Object processAutoHandlingCall2(ProceedingJoinPoint jp,
                                      CallSession callSession,
                                      FunctionalArea functionalArea,
                                      Object bean)
        throws Throwable {
    logger.debug("processAutoHandleCall");
   开发者_JAVA技巧 return jp.proceed();
}

With this call in my controller:

autoHandlingComponent.processAutoHandling(callSession, FunctionalArea.PRE_MAIN_MENU);

instead of

this.processAutoHandling(callSession, FunctionalArea.PRE_MAIN_MENU);


It seems that you are using Spring's proxy-based AOP. If so, this is a known limitation. See Understanding AOP Proxies from Spring documentation for more details. You have two ways to solve this issue:

  1. Use the AopContext.currentProxy() approach outlined in the documentation. I will discourage this approach, since your code will now be tied to Spring AOP quite explicitly.
  2. Use AspectJ's byte-code weaving. Since there is no proxy involved with it, you won't have the issue with 'this' pointing to original object and proxy is transparently available only to external objects.
0

精彩评论

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