2011-10-18 43 views
7

我需要創造,我覺得很難形容一個方面,所以讓我指出的觀點:Spring AOP的切入點與一個特定的參數

  • COM的包(或任何一個子包)中的任何方法。 XY ..
  • 一個方法的參數是一個接口的實現javax.portlet.PortletRequest
  • 有可能在方法我更多的參數
  • 他們可能會以任意順序

我需要一個切入點,並給出

目前的PortletRequest的 「繞」 的建議,我有SMT,如:

@Pointcut("execution(* com.x.y..*.*(PortletRequest,..)) && args(request,..)") 
public void thePointcut(PortletRequest request) { 
} 


@Around("thePointcut(request)") 
    public Object theAdvice(ProceedingJoinPoint joinPoint, PortletRequest request) { 
... 

,並收到一個錯誤:

ERROR 10:47:27.159 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] o.s.web.portlet.DispatcherPortlet - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet. mvc.HttpRequestHandlerAdapter': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: w arning no match for this type name: PortletRequest [Xlint:invalidAbsoluteTypeName]

任何幫助,高度讚賞

親切的問候, 丹

UPDATE 我試圖攔截的方法是:

公共類com.xyMainClass

public String mainRender(Model model, RenderRequest request) throws SystemException

公共類com.xyasd.HelpClass

public final void helpAction(ActionRequest request, ActionResponse response, Model model)

對於cource,我想獲得實現PortletRequest的參數,即第一個方法中的RenderRequest和第二個中的ActionRequest。

問候, 丹

回答

8

由於錯誤提示你需要在切入點表達式中使用PortletRequest的完全限定的名字 - 因爲它是在評估時的字符串進口方面不可用表達方式。

@Pointcut("execution(* com.x.y..*.*(javax.portlet.PortletRequest.PortletRequest,..)) && args(request,..)") 
public void thePointcut(PortletRequest request) { 
} 

既然你已經是選擇在ARGS類型構建你不需要在簽名。以下也應該工作。

@Pointcut("execution(* com.x.y..*.*(..)) && args(request,..)") 
public void thePointcut(PortletRequest request) { 
} 

這是一個布爾運算 - 即它需要匹配方法模式以及args構造。

+0

我不再接受錯誤,但切入點並沒有捕獲該方法。 更具體一點,請查看上面更新的帖子。 – Queequeg

+1

這兩種方法或只有mainRender方法。您定義點刪除的方式只會匹配第一個參數爲PortletRequest的那些方法。你可以嘗試類似args(..,request,..) - 不知道這是否可行。您還可以重新排序參數,以使PortletRequest成爲第一個參數。 – gkamal

+0

我想捕捉參數之間的PortletRequest的任何方法,並有權訪問該請求。 – Queequeg