Spring AOP切入点有一个特定的参数 [英] Spring AOP pointcut with one certain argument

查看:181
本文介绍了Spring AOP切入点有一个特定的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to create an aspect that I find hard to describe, so let me point out the ideas:


  • com.xy的包(或任何子包)..

  • 一个方法参数是接口javax.portlet.PortletRequest的实现

  • 有可能我在方法中有更多的论据

  • 它们可能是任何顺序

  • any method within the package (or any subpackage) of com.x.y...
  • one method argument is an implementation of an interface javax.portlet.PortletRequest
  • there may me more arguments in the method
  • they may be in any order

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

I need a pointcut and an "around" advice with the PortletRequest given

目前我有类似的东西:

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


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

并收到错误:


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

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]

任何帮助表示高度赞赏

亲切的问候,
Dan

Kind regards, Dan

UPDATE
我试图拦截的方法是:

UPDATE the method i'm trying to intercept is:

公共类com.xyMainClass 中:

public String mainRender(模型模型,RenderRequest请求)抛出SystemException

公共类com.xyasd.HelpClass

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

对于cource,我想得到实现PortletRequest的参数,即第一种方法的RenderRequest和第二种方法的ActionRequest 。

Of cource, I want to get the argument that implements PortletRequest, that is RenderRequest from the first method, and ActionRequest from the second.

问候,
Dan

Regards, Dan

推荐答案

作为错误暗示您需要在切入点表达式中使用PortletRequest的完全限定名称 - 因为它是一个字符串,导致上下文在表达式的评估期间不可用。

As the error suggests you need to use the fully qualified name of the PortletRequest in the point cut expression - since it is a string the import context is not available during the time of evaluation of the expression.

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

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

Since you already are selecting the type in the args construct you don't need that in the signature. The following should also work.

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

这是一个布尔运算 - 即需要匹配方法模式以及args构造。

It is a and boolean operation - i.e., it needs to match the method pattern as well as the args construct.

这篇关于Spring AOP切入点有一个特定的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆