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

相关推荐
yq1982043011562 小时前
静思书屋:基于Java Web技术栈构建高性能图书信息平台实践
java·开发语言·前端
一个public的class2 小时前
你在浏览器输入一个网址,到底发生了什么?
java·开发语言·javascript
有位神秘人2 小时前
kotlin与Java中的单例模式总结
java·单例模式·kotlin
golang学习记2 小时前
IntelliJ IDEA 2025.3 重磅发布:K2 模式全面接管 Kotlin —— 告别 K1,性能飙升 40%!
java·kotlin·intellij-idea
爬山算法2 小时前
Hibernate(89)如何在压力测试中使用Hibernate?
java·压力测试·hibernate
暮色妖娆丶3 小时前
SpringBoot 启动流程源码分析 ~ 它其实不复杂
spring boot·后端·spring
消失的旧时光-19433 小时前
第十四课:Redis 在后端到底扮演什么角色?——缓存模型全景图
java·redis·缓存
BD_Marathon3 小时前
设计模式——依赖倒转原则
java·开发语言·设计模式
BD_Marathon3 小时前
设计模式——里氏替换原则
java·设计模式·里氏替换原则
Coder_Boy_3 小时前
Deeplearning4j+ Spring Boot 电商用户复购预测案例中相关概念
java·人工智能·spring boot·后端·spring