Java 如何在@Query中使用类似hasAnyRole的表达式SpEl

Java 如何在@Query中使用类似hasAnyRole的表达式SpEl,java,spring,spring-security,spring-data-jpa,Java,Spring,Spring Security,Spring Data Jpa,我在@Query中使用了Spring安全表达式,如下示例所示: @Query("select o from Pet o where o.owner.name like ?#{hasRole('ROLE_ADMIN') ? '%' : principal.username}") 如果您的角色是ADMIN,则查询将返回所有宠物。但是,如果您没有此角色,查询将只返回所有者名称与经过身份验证的用户名称相同的Pet对象 这很好,但是当我尝试使用hasAnyRole('ROLE\u ADMIN','ROL

我在@Query中使用了Spring安全表达式,如下示例所示:

@Query("select o from Pet o where o.owner.name like ?#{hasRole('ROLE_ADMIN') ? '%' : principal.username}")
如果您的角色是ADMIN,则查询将返回所有宠物。但是,如果您没有此角色,查询将只返回所有者名称与经过身份验证的用户名称相同的Pet对象

这很好,但是当我尝试使用hasAnyRole('ROLE\u ADMIN','ROLE\u OWNER')时,系统返回一个异常

org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 0): Method call: Method hasAnyRole(java.lang.String,java.lang.String) cannot be found on java.lang.Object[] type
at org.springframework.expression.spel.ast.MethodReference.findAccessorForMetho
...
在SecurityExpressionRoot中定义了方法hasAnyRole:

public final boolean hasAnyRole(String... roles) {
    return hasAnyAuthorityName(defaultRolePrefix, roles);
}

我也有同样的问题,快速解决方法是编写
hasRole('ROLE\u SUPER')或hasRole('ROLE\u OWNER')

这个异常是由Spring数据引起的,就我在调试时所见,Spring数据无法解析SpEL中参数数目可变的方法。
扩展WareEvaluationContextProvider
方法解析程序与
hasAnyRole(字符串[])不匹配。

我创造了


编辑:这个问题已经解决,我刚刚测试了最新的快照,得到了
hasAnyRole
工作。

你能解决这个问题吗?谢谢