-
背景
-
自定义注解 + 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