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博客

相关推荐
一定要AK2 小时前
Spring 入门核心笔记
java·笔记·spring
A__tao2 小时前
Elasticsearch Mapping 一键生成 Java 实体类(支持嵌套 + 自动过滤注释)
java·python·elasticsearch
KevinCyao2 小时前
java视频短信接口怎么调用?SpringBoot集成视频短信及回调处理Demo
java·spring boot·音视频
凯尔萨厮2 小时前
创建SpringWeb项目(Spring2.0)
spring·mvc·mybatis
迷藏4942 小时前
**发散创新:基于Rust实现的开源合规权限管理框架设计与实践**在现代软件架构中,**权限控制(RBAC)** 已成为保障
java·开发语言·python·rust·开源
總鑽風3 小时前
搭建Spring Boot + ELK日志平台,实现可视化日志监控
spring boot·elk·macos
不吃香菜学java3 小时前
Redis简单应用
数据库·spring boot·tomcat·maven
wuxinyan1233 小时前
Java面试题47:一文深入了解Nginx
java·nginx·面试题
新知图书4 小时前
搭建Spring Boot开发环境
java·spring boot·后端
皮皮林5514 小时前
SpringBoot 4 最被低估的新特性:Spring Data AOT
spring boot