Null return value from advice does not match primitive return type for

    科技2025-09-12  76

    1.报错信息 Exception in thread “main” org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract int com.ldy.service.UserService.save(int,int) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:226) at com.sun.proxy.$Proxy19.save(Unknown Source) at App.main(App.java:9)

    2.运行环境

    @Around("pt()") public void around(ProceedingJoinPoint pjp) throws Throwable { System.out.println("before"); pjp.proceed(); System.out.println("after"); } public int save(int m, int n) { System.out.println("user service running"+m+","+n); return 100; }

    3.报错原因 环绕通知的返回值是Null,不匹配目标方法

    4.修改

    @Around("pt()") public Object around(ProceedingJoinPoint pjp) throws Throwable { System.out.println("around....before"); Object ret = pjp.proceed(); System.out.println("around....after"); return ret; }
    Processed: 0.016, SQL: 8