当前位置: 首页 > 知识库问答 >
问题:

SpelEvaluationException:EL1007E:(pos 43):在null上找不到字段或属性“group”

昝涛
2023-03-14

>

  • POJO摘要

    // User Class
    public class User {
        int id;
        String name;
        // getters and setters
    }
    
    // Group Class
    public class Group {
        int id;
        String name;
        // getters and setters
    }
    
    // GroupMembership class
    public class GroupMembership {
        private int id;
        private User user;
        private Group group;
        // getters and setters
    }
    

    对方法预授权筛选器。

    @PreAuthorize("canIEditGroupProfile(#membership.group.id)")
    public int updateGroupMembership(GroupMembership membership)
        throws GroupsServiceException;
    

    在传递完全填充的groupmembership对象(存在正确的用户和组组合)时,安全筛选器引发以下异常:

    errorMessage: "Failed to evaluate expression
        canIEditGroupProfile(#membership.group.id)'"
    

    原因是:

    org.springframework.expression.spel.SpelEvaluationException:
        EL1007E:(pos 33): Field or property 'group' cannot be found on null
    

    请提供地址相同的指针。

  • 共有1个答案

    轩辕煜
    2023-03-14

    getter/setter似乎很好...也没有null的情况。

    然而这是一个有趣的观察;这条给了我一个错误:

    @PreAuthorize("canIEditGroupProfile(#membership.group.id)")
    public int updateGroupMembership(GroupMembership membership)
        throws GroupsServiceException; 
    

    这很管用:

    @PreAuthorize("canIEditGroupProfile(#groupmembership.group.id)")
    public int updateGroupMembership(GroupMembership groupmembership)
        throws GroupsServiceException;
    
     类似资料: