gpt4 book ai didi

spring - Grails 2 - 无法创建 spring 安全域对象

转载 作者:行者123 更新时间:2023-11-29 11:21:26 25 4
gpt4 key购买 nike

运行 grails s2-quickstart com.testApplication.secureApplication User Role 后,我从 th grails 插件页面安装了 spring security 应用程序,以自动生成我执行的域对象 grails run-app 并得到这个异常:

|Loading Grails 2.3.4
|Configuring classpath
.
|Environment set to development
.................................
|Packaging Grails application
Precompiling AST Transformations ...
src C:\Users\GrailsWorkspace\testApplication\target\work\plugins\postgresql-extensions-0.6.1 C:\Users\GrailsWorkspace\testApplication\target\classes
Done precompiling AST Transformations!
..
|Compiling 3 source files
...................................................
|Running Grails application
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Error |
2013-12-15 15:42:45,635 [localhost-startStop-1] ERROR hbm2ddl.SchemaExport - Unsuccessful: create table user (id int8 not null, version int8 not null, account_expired bool not null, account_locked bool not null, enabled bool not null, "password" varchar(255) not null, password_expired bool not null, username varchar(255) not null unique, primary key (id))
Error |
2013-12-15 15:42:45,638 [localhost-startStop-1] ERROR hbm2ddl.SchemaExport - ERROR: syntax error at "user"
Position: 14
Error |
2013-12-15 15:42:45,688 [localhost-startStop-1] ERROR hbm2ddl.SchemaExport - Unsuccessful: alter table user_role add constraint FK143BF46A1E03E05D foreign key (user_id) references user
Error |
2013-12-15 15:42:45,688 [localhost-startStop-1] ERROR hbm2ddl.SchemaExport - ERROR: syntax error at "user"
Position: 90
|Server running.

问题是我的数据库配置正确,因为我得到了表 roleuser_role。但是,用户不会在我的 postgresql db 中生成。我对自动生成的 user domain object 的实现如下所示:

class User {

transient springSecurityService

String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired

static transients = ['springSecurityService']

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

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

Set<Role> getAuthorities() {
UserRole.findAllByUser(this).collect { it.role } as Set
}

def beforeInsert() {
encodePassword()
}

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

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

感谢您的回答!

最佳答案

'user' 是 Postgres 中的保留名称。您可以通过在域类中设置映射并使用备用名称来避免这种情况。

 static mapping = { table 'myusers' }

这样您的域类保持不变。您也可以像使用“密码”一样对名称进行转义。

关于spring - Grails 2 - 无法创建 spring 安全域对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20595783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com