SpelEvaluationException:EL1007E:(pos 43):在null上找不到字段或属性“group”
我为我的Web应用程序完全配置了SPRING METHOD安全性。 (启用PRE / POST注释)。
但最近我遇到了一个奇怪的问题。 总结如下:
-
POJOS摘要
// 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 }
-
PreAuthorise过滤方法。
@PreAuthorize("canIEditGroupProfile(#membership.group.id)") public int updateGroupMembership(GroupMembership membership) throws GroupsServiceException;
传递完全填充的GroupMembership
对象(存在适当的用户和组合成)时,安全筛选器将引发以下exception:
errorMessage: "Failed to evaluate expression canIEditGroupProfile(#membership.group.id)'"
在挖掘exception时:
原因是:
org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 33): Field or property 'group' cannot be found on null
请提供相同的指示。
getter / setters看起来很好……也没有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;
我进一步观察到,参数名称在第一个的情况下是不匹配的(即Service和ServiceImpl都有不同的参数名称)。
现在保持一致性,问题似乎是固定的。
我在Spring Boot应用程序中遇到了同样的问题。 事实certificate,我正在编译时没有我的调试符号信息,正如上面的评论中提到的那样。 我想说的是我可以通过两种方式解决问题:
1.(我最喜欢的):只需将它包含在你的pom.xml – >插件中
org.apache.maven.plugins maven-compiler-plugin -parameters -parameters
- 如果您使用Java 1.8和Eclipse作为IDE,请转到项目属性 – > Java编译 – >选中“存储有关方法参数的信息(可通过reflection使用)”。
我发现这个链接非常有趣,可以更多地了解这个问题。
希望能帮助到你!
正如@zeroflagL问的那样:你是否在没有调试信息的情况下进行编译? 这可能与使用Ehcache的spring @Cacheable, 使用SpEL键的spel find null和使用SpEL键的Spring @Cacheable相同:始终求值为null – 检查您的POM(或Eclipse配置或其他)以获取调试配置,例如maven-compiler-plugin
中的
。
- generics和类<? 扩展Enum >,EnumSet.allOf(class)vs class.getEnumConstants()
- 扩展密钥库证书的有效时间
- 在Java代码中访问Drools返回的事实对象
- 使用Google Guice和静态方法注入Util类?
- 我得到了这个seleniumexception:在尝试使用java和Appium运行测试时尚未实现Method
- JUnit :(可能是间接的)将自己包含在SuiteClass中
- ACTIVEMQ-发布者订阅者hello world示例
- 从servlet访问JSF会话作用域bean,由嵌入在JSF webapp中的applet调用
- 我怎么能创建.jar文件?