【发布时间】:2011-03-02 15:34:44
【问题描述】:
我正在使用 Spring Security Plugin 在我的 Grails 应用程序中管理成员资格和身份验证。
我正在尝试通过一对一关联将 User 域类与 Profile 域相关联。
我在 User.groovy 上添加了这些行:
static hasOne = [userProfile:UserProfile]
static constraints = {
//...
userProfile unique:true
}
到 UserProfile.groovy:
User user
唉,我在调用 UseRole.create(user,role) 时出错了。
关于如何获得我正在寻找的相同功能,有一些最佳实践。特别是,我想将任何用户与一个配置文件对象相关联以对其进行扩展。
然后我还想添加与帖子和其他表的一对多关系...
谢谢 最好的问候
PS: 我收到此错误:
配置 Spring Security UI ... 2011-03-08 12:18:51,179 [main] 错误 context.GrailsContextLoader - 执行引导程序时出错:null java.lang.NullPointerException 在 $Proxy19.save(未知来源) 在 com.dromedian.xxxxx.security.UserRole.create(UserRole.groovy:32) 在 com.dromedian.xxxxx.security.UserRole$create.call(未知来源) 在 BootStrap$_closure1.doCall(BootStrap.groovy:20) 在 grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:251) 在 grails.util.Environment.executeForEnvironment(Environment.java:244) 在 grails.util.Environment.executeForCurrentEnvironment(Environment.java:220) 在 org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212) 在 grails.web.container.EmbeddableServer$start.call(未知来源) 在 _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158) 在 _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy) 在 _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280) 在 _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy) 在 _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149) 在 _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy) 在 _GrailsRun_groovy.runInline(_GrailsRun_groovy:116) 在 _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy) 在 _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59) 在 RunApp$_run_closure1.doCall(RunApp.groovy:33) 在 gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) 在 gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) 在 gant.Gant$_dispatch_closure7.doCall(Gant.groovy) 在 gant.Gant.withBuildListeners(Gant.groovy:427) 在 gant.Gant.this$2$withBuildListeners(Gant.groovy) 在 gant.Gant$this$2$withBuildListeners.callCurrent(未知来源) 在 gant.Gant.dispatch(Gant.groovy:415) 在 gant.Gant.this$2$dispatch(Gant.groovy) 在 gant.Gant.invokeMethod(Gant.groovy) 在 gant.Gant.executeTargets(Gant.groovy:590) 在 gant.Gant.executeTargets(Gant.groovy:589) 应用程序上下文正在关闭...
配置是:
User.groovy(spring security插件创建的域类)
static hasOne = [userDetail:UserDetail]
static constraints = {
username blank: false, unique: true
password blank: false
userDetail unique:true
}
UserDetail.groovy
static hasOne = [user:User]
static belongsTo = User
BootStrap.groovy
//TODO temporary added - no for production or persistent db
def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
def userRole = new Role(authority: 'ROLE_USER').save(flush: true)
String password = springSecurityService.encodePassword('password')
def testUser = new User(username: 'me', enabled: true, password: password)
testUser.save(flush: true)
if(testUser != null){
UserRole.create testUser, adminRole, true
}
如果我不打电话
UserRole.create testUser, adminRole, true
没有错误。我尝试调试,但我能理解错误在哪里。
【问题讨论】:
-
您需要向我们显示错误消息,因为我们没有神奇的力量来查看您的屏幕。 ;)
-
您必须更具体地了解您收到的错误消息的位置和内容。
-
对不起,我现在发布错误信息:)
标签: security spring plugins grails grails-orm