Spring AOP切入点有一个特定的参数

Que*_*ueg 8 java aop spring

我需要创建一个我难以描述的方面,所以让我指出这些想法:

  • com.xy的包(或任何子包)中的任何方法..
  • 一个方法参数是接口javax.portlet.PortletRequest的实现
  • 这个方法中可能有更多的参数
  • 他们可能是任何顺序

我需要一个切入点和给出的PortletRequest的"around"建议

目前我有点像:

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


@Around("thePointcut(request)")
    public Object theAdvice(ProceedingJoinPoint joinPoint, PortletRequest request) {
...
Run Code Online (Sandbox Code Playgroud)

并收到错误:

错误10:47:27.159 [ContainerBackgroundProcessor [StandardEngine [Catalina]]] osweb.portlet.DispatcherPortlet - 上下文初始化失败org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.web.servlet的bean时出错.mvc.HttpRequestHandlerAdapter':bean的初始化失败; 嵌套异常是java.lang.IllegalArgumentException:w arning此类型名称不匹配:PortletRequest [Xlint:invalidAbsoluteTypeName]

任何帮助高度赞赏

亲切的问候,丹

更新 我试图拦截的方法是:

公共类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.

问候,丹

gka*_*mal 11

由于错误建议您需要在切入点表达式中使用PortletRequest的完全限定名称 - 因为它是一个字符串,导致上下文在评估表达式时不可用.

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

由于您已经在args构造中选择了类型,因此签名中不需要该类型.以下也应该有效.

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

它是一个布尔运算 - 也就是说,它需要匹配方法模式以及args构造.

  • 两种方法或只有 mainRender 方法。您定义切入点的方式只会匹配第一个参数是 PortletRequest 的方法。您可以尝试类似 args(..,request,..) 之类的方法 - 不确定这是否可行。您还可以对参数重新排序,以便将 PortletRequest 作为第一个参数。 (2认同)
  • 有没有人弄清楚这一点?我对方法签名中任意顺序的给定类型的参数也有同样的问题。 (2认同)