Spring-AOP环绕监听出错
2024-10-10 08:31:49
Exception in thread "main" org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public int aoppoint.User.getUsername()
at org.springframework.aop.framework.CglibAopProxy.processReturnType(CglibAopProxy.java:391)
at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:82)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:675)
at aoppoint.User$$EnhancerBySpringCGLIB$$ab381b5d.getUsername(<generated>)
at aoppoint.Console.main(Console.java:25)
public void logAround(ProceedingJoinPoint joinPoint) {
System.out.println("userbean方法执行之前 Around,切入的名字 : " + joinPoint.getSignature().getName());
try {
joinPoint.proceed(); //阻塞
System.out.println("userbean方法执行之后 Around,切入的名字 : " + joinPoint.getSignature().getName());
} catch (Throwable throwable) {
throwable.printStackTrace();
System.out.println("userbean方法执行出错 Around,切入的名字 : " + joinPoint.getSignature().getName());
}
}
后来发现是环绕监听会对有返回值的方法做处理,所以需要对 logAround方法修改一下,让它有一个返回值,返回object就可以了
public Object logAround(ProceedingJoinPoint joinPoint) {
System.out.println("userbean方法执行之前 Around,切入的名字 : " + joinPoint.getSignature().getName());
Object result=null;
try {
result = joinPoint.proceed();//阻塞
System.out.println("userbean方法执行之后 Around,切入的名字 : " + joinPoint.getSignature().getName());
} catch (Throwable throwable) {
throwable.printStackTrace();
System.out.println("userbean方法执行出错 Around,切入的名字 : " + joinPoint.getSignature().getName());
}
return result;
}
最新文章
- 解析C#类中的构造函数
- Redis系列三之持久化
- c# dynamic动态类型和匿名类
- POJ 3225 (线段树 区间更新) Help with Intervals
- [Locked] Range Sum Query 2D - Mutable
- C#泛型比较大小
- boost::share_ptr用法
- jq 测试是否到页面最底端
- CentOS6 图形界面(gnome)安装,使用vnc进行远程连接
- vue中显示静态图片怎么引用
- Oracle和Mysql的安装
- rest_framework中视图相关
- linux下GCC编译文件
- 分布式任务调度系统xxl-job搭建
- ERP合同管理流程查询(三十一)
- Azure Document DB Repository 的实现
- java.io.PrintWriter 中 write() 与 print() 的区别
- eclipse怎么导出可执行jar包
- PL/SQL 编程(二)
- linux 基本命令___0003 字符串处理和yum安装软件的路径