gpt4 book ai didi

aop - 切入点将所有方法与自定义注释匹配

转载 作者:行者123 更新时间:2023-12-04 21:43:30 28 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
@AspectJ pointcut for all methods of a class with specific annotation

我正在尝试为具有自定义注释的类的所有方法编写一个切入点。这是代码

  • 注释:

    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;

    @Retention(value = RetentionPolicy.RUNTIME)
    @Target(value = ElementType.METHOD)
    public @interface ValidateRequest {}
  • Controller 中的方法:

     @RequestMapping(value = "getAbyB", produces = "application/json")
    @ResponseBody
    @ValidateRequest
    public Object getAbyB(@RequestBody GetAbyBRequest req) throws Exception {
    /// logic
    }
  • 看点:

     @Aspect
    @Component
    public class CustomAspectHandler {
    @Before("execution(public * *(..))")
    public void foo(JoinPoint joinPoint) throws Throwable {
    LOG.info("yippee!");
    }
    }
  • 应用上下文:

    `<aop:aspectj-autoproxy />`

我一直在尝试下面提到的各种建议,但似乎都没有用(除了上面使用的那个)

  • @Around("@within(com.pack.Anno1) || @annotation(com.pack.Anno1)")
  • @Around("执行(@com.pack.Anno1 * *(..))")

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com