1.问题复现
//从spring上线文获取实现TestService接口的实现类
Map<String, TestService> beansOfType = ContextUtil.getApplicationContext().getBeansOfType(TestService.class);
//通过isAnnotationPresent(class) 方法过滤出想要的注解
List<Method> collect = methodsList.stream().filter(method -> method.isAnnotationPresent(Test.class)).collect(Collectors.toList());
//结果List == null
2.解决方法
//使用AnnotationUtils.findAnnotation()方法 获取原本被代理的原对象
List<Method> methodsList = methodsList.stream().filter(method -> AnnotationUtils.findAnnotation(method, Test.class) != null).collect(Collectors.toList());
3.问题原因
aop实现代理类, 获取的是代理类中的注解, 而代理类中注解直接没有生成,导致失败
如图:
图片.png
网友评论