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

相关推荐
若鱼19196 分钟前
SpringBoot4.0新特性-Observability让生产环境更易于观测
java·spring
倒流时光三十年9 分钟前
SpringBoot 数据库同步 Elasticsearch 性能优化
数据库·spring boot·elasticsearch
觉醒大王15 分钟前
强女思维:着急,是贪欲外显的相。
java·论文阅读·笔记·深度学习·学习·自然语言处理·学习方法
努力学编程呀(๑•ี_เ•ี๑)23 分钟前
【在 IntelliJ IDEA 中切换项目 JDK 版本】
java·开发语言·intellij-idea
码农小卡拉32 分钟前
深入解析Spring Boot文件加载顺序与加载方式
java·数据库·spring boot
向上的车轮40 分钟前
为什么.NET(C#)转 Java 开发时常常在“吐槽”Java:checked exception
java·c#·.net
Dragon Wu41 分钟前
Spring Security Oauth2.1 授权码模式实现前后端分离的方案
java·spring boot·后端·spring cloud·springboot·springcloud
跳动的梦想家h1 小时前
环境配置 + AI 提效双管齐下
java·vue.js·spring
坚持就完事了1 小时前
Java中的集合
java·开发语言
wjhx1 小时前
QT中对蓝牙权限的申请,整理一下
java·数据库·qt