Null return value from advice does not match primitive

Exception in thread "main" org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public int com.fanling.xmlaop.UserDaoImpl.addUser(com.fanling.xmlaop.User)
	at org.springframework.aop.framework.CglibAopProxy.processReturnType(CglibAopProxy.java:391)
	at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:84)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:690)

这个错就是返回的类型不匹配。

造成的原因:

目标类的方法有返回值,而around环绕方法没有返回值

解决方法

CglibAopProxy.java类
@Nullable
    private static Object processReturnType(Object proxy, @Nullable Object target, Method method, @Nullable Object returnValue) {
        if (returnValue != null && returnValue == target && !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
            returnValue = proxy;
        }

        Class<?> returnType = method.getReturnType();
        if (returnValue == null && returnType != Void.TYPE && returnType.isPrimitive()) {
            throw new AopInvocationException("Null return value from advice does not match primitive return type for: " + method);
        } else {
            return returnValue;
        }
    }

方法1:将int 改为包装类型不报错

方法2:修改around的方法,修改为Object返回类型

    public Object around(ProceedingJoinPoint pjt ){
        Object object = null;
        try {
            System.out.println("环绕通知");
            object= pjt.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return object;
    }

  

原文地址:https://www.cnblogs.com/fanling521/p/10523959.html

时间: 2024-10-09 21:54:49

Null return value from advice does not match primitive的相关文章

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list.

图解: 此题过程分为三个阶段,分别是 1.负责后面一个节点,并且将这个节点插入到原来链表中  2.复制后面一个节点的random指针. 3 拆分组合链表为两部分. 第一部分代码: while(currentnode!=null){//复制节点,并且将节点插入到该节点的后面 RandomListNode clonenode=new RandomListNode(currentnode.label); clonenode.next=currentnode.next; currentnode.next

cannot be translated into a null value due to being declared as a primitive type. Consid

1 严重: Servlet.service() for servlet [note-portal] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Optional long parameter 'noteBookId' is present but cannot be translated into a

Null value was assigned to a property of primitive type setter of

解决办法: bean里的int 类型替换成 Integer .hbm.xml  改为java.lang.Integer Null value was assigned to a property of primitive type setter of,布布扣,bubuko.com

[hibernate]org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.wa.dataprocess.query.model.AcrossDeptApply 包装类和基本数据类型的区别, 包装类默认为null,基本类型为0. public class AcrossDeptApply implements Serializable private Str

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type sette

org.hibernate.PropertyAccessException: Null value was assigned to a property <property column="sex"  name="sex"  type="java.lang.Boolean"/> JavaBean修改:private Boolean sex; 原因:数据库字段值为NULL,int 类型不能赋值为NULL,只能为0,但有些实际应用中,如学

Null value was assigned to a property of primitive type setter of&quot;原因及解决方法

原文:http://blog.csdn.net/kevinzhangfei/article/details/6995316 总结:在Java中使用大写的数据类型. 在action请求数据的过程中报出"Null value was assigned to a property of primitive type setter of"错误,搜索之后发现是因为数据库里相应的字段为NULL. 例如: Java代码 <!--Hibernate映射文件中的字段--> <prope

org.hibernate.PropertyAccessException:Null value was assigned to a property of primitive type setter

在项目开发中遇到下面的异常:org.hibernate.PropertyAccessException:Null value was assigned to a property of primitive type setter ofcom.atguigu.surveypark.model.Page.orderno 这个异常的解释是:      Null值被分配给了设置为基本类型的Page类里的orderno属性.也就是说Null是不能分配给基本数据类型的.解决办法:手动给数据库中是Null值的

[转]Null value was assigned to a property of primitive type setter of&quot;原因及解决方法

原文地址:http://blog.csdn.net/kevinzhangfei/article/details/6995316 在action请求数据的过程中报出"Null value was assigned to a property of primitive type setter of"错误,搜索之后发现是因为数据库里相应的字段为NULL. 例如: Java代码 <!--Hibernate映射文件中的字段--> <property name="pri

hibernate.PropertyAccessException: Null value was assigned to a property of primitive type

日志: [WARN-2016/07/26/18/:45/:52]ProcessEngineServiceImpl.(257) - 审批流程log日志--submitProcess方法:提交人userId:3333333349,TaskId:245959,ProcInstId:null,WfInstaceId:16583386853,当前时间:Tue Jul 26 18:45:52 CST 2016 [ERROR-2016/07/26/18/:45/:52]ProjectRepayControll