• 首页
  • 栏目
  • ERP
  • AspectJ自定义注解报错:error Type referred to is not an annotation type:xxx -----...

AspectJ自定义注解报错:error Type referred to is not an annotation type:xxx -----...

  • 2021-11-17
  • Admin
  • 背景

    • 自定义注解 + AOP实现具体注解功能

    • 报错信息

      Caused by:java.lang.IllegalArgumentException: error Type referred to is not an annotation type: xxx(xxx是注解名称)

    • 语法用法

      within(@com.example.gongjin28.controller.AnnotationController *)
      匹配com.example.gongjin28.controller包及子包下带有@AnnotationController注解的任何类的任何方法

  • 添加注解的代码

    /**
     * @Desc 被代理的类
     * @Auther gongjin28
     */
    @Controller
    @RequestMapping("/controller")
    public class AnnotationController {
        /**
         * 注解测试方法:限制60秒内只能请求300次
         */
        @RequestMapping("/annotation")
        @RequestLimit(count = 300, time = 60)
        public void annotationTest() {
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

   

  • 切面代码

    /**
     * @Desc 请求限制注解测试
     * @Auther gongjin28
     */
    @Component
    @Aspect
    public class RequestLimitTest {
    
        @Before("within(@com.example.gongjin28.controller.AnnotationController *)&&@annotation(requestLimit)")
        public void requestLimit(final JoinPoint joinPoint, RequestLimit requestLimit) {
        
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

   

  • 问题解决

    1、注解的引用名称不一样在这里插入图片描述2、语法问题(包括但不限于以下语法问题,包括路径错误等)在这里插入图片描述
    3、缓存问题
         3.1、清理一下idea缓存
         3.2、再maven clean一下
         3.3、搞定

原文:https://blog.csdn.net/gongjin28_csdn/article/details/121378217

联系站长

QQ:769220720