栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

  • 背景
    • 自定义注解 + 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注解的任何类的任何方法

  • 添加注解的代码
    @Controller
    @RequestMapping("/controller")
    public class AnnotationController {
        
        @RequestMapping("/annotation")
        @RequestLimit(count = 300, time = 60)
        public void annotationTest() {
        }
    }
    

   

  • 切面代码
    @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、缓存问题
         3.1、清理一下idea缓存
         3.2、再maven clean一下
         3.3、搞定
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/531942.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号