grails - 无法使用 Spring Security 在 grails 2.1.1 中创建用户对象

标签 grails spring-security grails-2.0

我有以下类(class)

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)
    }
}

我在 Bootstrap 中调用以下代码
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 安全插件。

最佳答案

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

关于grails - 无法使用 Spring Security 在 grails 2.1.1 中创建用户对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12645996/

相关文章:

hibernate - 更新域类和刷新 session ?

java - 在带有 CrossOrigin 注释的 Java 中或在 Spring-Config XML 中使用 Spring Properties

java - 使用 spring session ID cookie 进行单点登录?

java - 升级到 Spring Security 4 后尝试登录时出现 404

grails - 无法使用Groovy访问参数图

grails - Grails中口音不敏感的搜索-创建条件

java - 当 grails 中的日期发生变化时,计时器任务执行了很多次

grails - 如何将 GSP 呈现为字符串?

unit-testing - Grails Spock单元测试查询

sql - 如何在Groovy/Grails Spoc中模拟SQL调用