如何使用参数化注释指定方法及其使用@Pointcut 的值

How can I specify method with an parameterized annotation and its value with @Pointcut

背景:

我正在使用 Spring MVC 开发 Web 应用程序。

我想创建一个在 POST 请求上执行而不是在 GET 请求上执行的方面,因为我想注入阻止 POST 请求完成之前发送的逻辑 HTML渲染。

@RequestMapping(value = "/aaa", method = RequestMethod.POST)
public String methodForPost(AnDto dto, Model model) {
    // the aspect should be executed on this method
}

@RequestMapping(value = "/bbb", method = RequestMethod.GET)
public String methodForGET(AnDto dto, Model model) {
    // the aspect shouldn't be executed on this method
}

问题:

  1. 如何使用参数化注释指定方法及其值 @Pointcut
  2. 如何在 Spring applicationContext.xml 中指定具有参数化注释的方法及其在 <aop:pointcut> 中的值?
@Around(value="@annotation(RequestMapping)")
public Object display(ProceedingJoinPoint joinPoint, RequestMapping requestMapping ) throws Throwable {
    // You have access to requestMapping. From which you can get whether its get or post and decide to proceed or not.
}

更多信息http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-ataspectj-advice-params-passing

您可能需要扩展它以仅拦截包中的 Requestmapping。因为这会拦截您项目中可能拥有的每个 RequestMappig,包括您可能正在使用的库使用的 RequestMappig,这是一种负担。