grails 中的字符串不是字符串吗?
这个错误在我身上发生过无数次,通常我会找到一种不使用字符串的方法,但这非常令人沮丧。
时不时就会出现这样的错误:
执行控制器的操作[编辑] [edu.drexel.goodwin.events.web.EventController] 引发异常: groovy.lang.MissingMethodException:否 方法签名: grails.plugins.springsecurity.SpringSecurityService.ifAllGranted() 适用于参数类型: (java.lang.String) 值: [ROLE_SUPER_ADMIN]”
我正在使用的代码如下所示:
springSecurityService.ifAllGranted(new String("ROLE_SUPER_ADMIN"))
我也尝试了以下所有方法均无济于事:
springSecurityService.ifAllGranted("ROLE_SUPER_ADMIN")
springSecurityService.ifAllGranted("""ROLE_SUPER_ADMIN""")
springSecurityService.ifAllGranted('ROLE_SUPER_ADMIN')
springSecurityService.ifAllGranted('''ROLE_SUPER_ADMIN''')
基本上就好像每个字符串变量都立即转换为存储在字符串中的值...但是如何做你真的使用字符串变量吗?
非常感谢你的帮助, -阿萨夫
This error has happened to me countless times, and usually I find a way to not use Strings, but it's incredibly frustrating.
Every now and then an error such as this one occurs:
Executing action [edit] of controller
[edu.drexel.goodwin.events.web.EventController]
caused exception:
groovy.lang.MissingMethodException: No
signature of method:
grails.plugins.springsecurity.SpringSecurityService.ifAllGranted()
is applicable for argument types:
(java.lang.String) values:
[ROLE_SUPER_ADMIN]"
The code I'm using looks like this:
springSecurityService.ifAllGranted(new String("ROLE_SUPER_ADMIN"))
I've also tried all of the following to no avail:
springSecurityService.ifAllGranted("ROLE_SUPER_ADMIN")
springSecurityService.ifAllGranted("""ROLE_SUPER_ADMIN""")
springSecurityService.ifAllGranted('ROLE_SUPER_ADMIN')
springSecurityService.ifAllGranted('''ROLE_SUPER_ADMIN''')
It's basically as if EVERY string variable is immediately turned into the value stored in the string... but how do you actually use string variables?
Thank you very much for your help,
-Asaf
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定问题不是字符串问题,而是“错误使用 API”问题。检查文档:
http://burtbeckwith.github.com /grails-spring-security-core/docs/manual/index.html
我在
SpringSecurityService
类上没有看到ifAllGranted
。我相信它曾经存在于旧版本的 SpringSecurity(即 Acegi)中。尝试使用 SpringSecurityUtils.ifAllGranted 而不是 springSecurityService 。如果您对它的工作原理感兴趣,请使用来源,卢克。
Im pretty sure the issue is not a String issue, its a "using the API incorrectly" issue. Check the documentation:
http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/index.html
Im not seeing
ifAllGranted
on theSpringSecurityService
class. I believe it used to be there in older versions of SpringSecurity (i.e. Acegi).Try using
SpringSecurityUtils.ifAllGranted
instead of springSecurityService. If you are interested in how it works, use the source, luke.