【发布时间】:2011-05-19 14:14:26
【问题描述】:
这个错误在我身上发生过无数次,通常我会找到一种不使用字符串的方法,但这非常令人沮丧。
时不时会出现这样的错误:
控制器的执行动作[编辑] [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''')
基本上就好像每个字符串变量都立即变成了存储在字符串中的值......但是你如何实际使用字符串变量?
非常感谢您的帮助, -阿萨夫
【问题讨论】:
-
永远不要使用
new String(string)- 只在传入字节数组时创建一个新字符串。字符串是不可变的和缓存的,因此创建一个与另一个值相同的新 String 实例是非常浪费的。