SpringBoot 切面AOP获取注解为null

复制代码
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        Method realMethod = joinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), method.getParameterTypes());
        XxxxAnnotation xxxxAnnotation= realMethod.getDeclaredAnnotation(XxxxAnnotation.class);

解决方法:

  • 直接用 method.getDeclaredAnnotation(XxxxAnnotation.class) 获取注解为null
  • 需要用方法的代理原始目标类取获取注解 realMethod.getDeclaredAnnotation(XxxxAnnotation.class)

解决 getAnnotation为null的坑_field.getannotation为空-CSDN博客

相关推荐
程序猿小蒜2 小时前
基于springboot的汽车资讯网站开发与实现
java·前端·spring boot·后端·spring
q***98522 小时前
前端的dist包放到后端springboot项目下一起打包
前端·spring boot·后端
vx_bisheyuange2 小时前
基于SpringBoot的热门旅游推荐系统设计与实现
java·spring boot·后端·毕业设计
代码不停2 小时前
Java分治算法题目练习(快速/归并排序)
java·数据结构·算法
代码or搬砖2 小时前
SpringBoot整合SpringMVC
java·spring boot·后端
程序定小飞2 小时前
基于springboot的汽车资讯网站开发与实现
java·开发语言·spring boot·后端·spring
Kapaseker3 小时前
Java 26 的新特性
java
糖纸风筝3 小时前
Java指南:eclipse、java-activemq与测试验证
java·开发语言·学习
小坏讲微服务3 小时前
整合Spring Cloud Alibaba与Gateway实现跨域的解决方案
java·开发语言·后端·spring cloud·云原生·gateway