SpringAop切面实现日志记录
代码实现:https://www.cnblogs.com/wenjunwei/p/9639909.html

问题记录

1.signature.getMethod().getAnnotation()无法获取注解对象

原因:Spring在处理中,可能是因为我的项目有事务,serviceImpl的方法被代理后直接得不到了。换一个思路:先得到自己的父类,然后通过父类得到真实的自己
解决方法:
https://www.cnblogs.com/wangshen31/p/9498731.html

 1 /**
2 * 这个方法帮忙拿出注解中的operation属性
3 * 因为有拦截serviceImpl的方法,而这些方法又加了事务管理,也就是这里也有aop,这些已经是代理类,用之前的写法获得的是代理类的方法,而这些
4 * 方法是特么不会把父类中的方法的注解加上去的!!!
5 * @param proceedingJoinPoint
6 */
7 private String getOperationOfTheAnnotation(ProceedingJoinPoint proceedingJoinPoint) throws Exception {
8
9 Signature signature = proceedingJoinPoint.getSignature();//方法签名
10 Method method = ( (MethodSignature)signature ).getMethod();
11
12 //这个方法才是目标对象上有注解的方法
13 Method realMethod = proceedingJoinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), method.getParameterTypes());
14
15
16 AuthorizationNeed authorizationNeed = realMethod.getAnnotation(AuthorizationNeed.class);
17
18 return authorizationNeed.operation();
19
20
21 }

2.signature.getParameterNames() 获取不到值

原因:如果您的bean实现了接口,那么JDK代理将在spring之前创建,并且在这种代理中,MethodSignature.getParameterNames()为null。
如果您的bean没有实现接口,则会创建CGLIB代理,并在其中填充MethodSignature.getParameterNames()。
解决方案:
http://www.it1352.com/990863.html
使用CGLIB代理,spring.aop.proxy-target-class: true (设置为true)

1 server:
2 port:8087
3 spring:
4 aop:
5 auto: true #启动aop配置
6 proxy-target-class: true

最新文章

  1. Microsoft.CodeAnalysis 入门
  2. Riot - 比 Facebook React 更轻量的 UI 库
  3. UVA 1314 最小表示法
  4. 【leetcode】4Sum
  5. hdu 1874(Dijkstra + Floyd)
  6. HDU 1698 区间更新
  7. JNI_Android项目中调用.so动态库实现详解【转】
  8. Socket与TcpClient的区别(转载)
  9. Html特殊字符转义处理
  10. 信息收集->DNS分析->dnsdict6
  11. 三种情形容易引起Azure虚拟机重新启动
  12. iOS中ARC内部原理
  13. 根据文字计算Label的尺寸
  14. Flask的session——关于写扩展所学习到的
  15. seajs进行模块化开发
  16. 01-.Net编程机制
  17. [Android 除錯] Conflict with dependency
  18. SharePoint 2013 拷贝文件夹到本地
  19. python 使用selenium模块爬取同一个url下不同页的内容(浏览器模拟人工翻页)
  20. new Date()浏览器兼容性问题

热门文章

  1. 自动化遍历-appcrawler
  2. Django ORM Queryset 的缓存机制, 惰性查询简述
  3. ubuntu JDK&SDK 环境变量配置
  4. update不能直接使用select的返回结果
  5. Linux入门到放弃之二《目录处理常用命令的使用方法》
  6. 这是2020年最强Python学习路线,从入门到精通!
  7. LIS初级推算(最长上升子序列问题)
  8. IntelliJ IDEA 2020.2 x64 激活 2020-09-18亲测有效
  9. localStorage.getItem得到的是[object Object] 的解决方案
  10. new 正则