2011-01-22 211 views
1

内特定的切入点,我开始与原来的问题上 Need help creating a specific pointcut that utilizes a value from a method annotation需要帮助建立的方法

我决定,我想问一个问题,以改变我采用的方法。 我有一个方法(导航),该方法内有一个调用另一个方法,我希望有@Around建议。

@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); 
} 

这是可能的,因为我似乎无法得到这个工作,如果方法是在同一类内。

这工作,如果它不是对对象本身:

@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"); 
    return jp.proceed(); 
} 

通过此调用在我的控制器:中

autoHandlingComponent.processAutoHandling(callSession, FunctionalArea.PRE_MAIN_MENU); 

代替

this.processAutoHandling(callSession, FunctionalArea.PRE_MAIN_MENU); 

回答

1

看来你是使用Spring的基于代理的AOP。如果是这样,这是一个已知的限制。有关更多详细信息,请参阅Spring文档中的Understanding AOP Proxies。您有两种方法可以解决此问题:

  1. 使用文档中概述的AopContext.currentProxy()方法。我会劝阻这种方法,因为你的代码现在已经非常明确地与Spring AOP绑定了。
  2. 使用AspectJ的字节码编织。由于没有涉及代理的代理,因此您不会遇到'this'指向原始对象的问题,代理仅透明地可用于外部对象。