【问题标题】:Cannot Create User Object in grails 2.1.1 using Spring Security无法使用 Spring Security 在 grails 2.1.1 中创建用户对象
【发布时间】:2012-09-20 16:36:27
【问题描述】:

我有以下课程

class SentryUser {

    transient springSecurityService

    String userName
    String password
    boolean enabled
    boolean accountExpired = false
    boolean accountLocked = false
    boolean passwordExpired   = false

    static constraints = {
        userName blank: false, unique: true
        password blank: false
    }

    static mapping = {
        password column: '`password`'
    }

    Set<SentryRole> getAuthorities() {
        SentryUserSentryRole.findAllBySentryUser(this).collect { it.sentryRole } as Set
    }

    def beforeInsert() {
        encodePassword()
    }

    def beforeUpdate() {
        if (isDirty('password')) {
            encodePassword()
        }
    }

    protected void encodePassword() {
        password = springSecurityService.encodePassword(password)
    }
}

我在引导程序中调用以下代码

def admin = new SentryUser(userName: "sample@sample.com",
                enabled: true).save(failOnError: true)

并得到以下错误

context.GrailsContextLoader Error executing bootstraps: groovy.lang.MissingMethodException: No signature of method: SentryUser.save() is applicable for argument types: () values: []

我正在使用 grails 2.1.1 并使用 spring 安全插件。

【问题讨论】:

    标签: grails spring-security grails-2.0


    【解决方案1】:

    您正在调用 save(Map),但 MME 抱怨 save() 没有任何参数。在我的应用程序中没有安装任何持久性插件(hibernate/mongodb)之前,我已经看到了这种差异——它是一个插件项目,我试图作为独立应用程序运行,而新插件项目的默认 BuildConfig不包括对休眠的依赖。

    【讨论】:

    • 这就是原因......我必须在我的项目中添加休眠功能,然后就成功了
    猜你喜欢
    • 2012-09-15
    • 2011-10-31
    • 2012-07-26
    • 2012-06-08
    • 2012-06-02
    • 2012-11-04
    • 2015-06-02
    • 2015-03-27
    • 2020-04-06
    相关资源
    最近更新 更多