grails新安全插件提供空指针异常

grails新安全插件提供空指针异常,grails,grails-plugin,Grails,Grails Plugin,我在Bootstrap.groovy中添加了以下代码,这是在安全核心插件教程之后直接添加的,我从Bootstrap.groovy中得到了一个空指针异常。你知道怎么了吗 谢谢,雷 另外,我使用推荐插件推荐的s2 quickstart命令添加了User和Role类,该命令生成User、Role和UserRole域类。下一步是在Bootstrap中设置一些示例用户,但失败了 Bootstrap.groovy: println "Creating roles user, leader,

我在Bootstrap.groovy中添加了以下代码,这是在安全核心插件教程之后直接添加的,我从Bootstrap.groovy中得到了一个空指针异常。你知道怎么了吗

谢谢,雷

另外,我使用推荐插件推荐的s2 quickstart命令添加了User和Role类,该命令生成User、Role和UserRole域类。下一步是在Bootstrap中设置一些示例用户,但失败了


Bootstrap.groovy:

       println "Creating roles user, leader, and admin"
       def userRole = Role.findByAuthority("ROLE_USER") ?: new Role(authority: "ROLE_USER").save()
       def leaderRole = Role.findByAuthority("ROLE_LEADER") ?: new Role(authority: "ROLE_LEADER").save()
       def adminRole = Role.findByAuthority("ROLE_ADMIN") ?: new Role(authority: "ROLE_ADMIN").save()

       println "Creating users called user, leader, and admin"
       def user = new User(username: "user", password: springSecurityService.encodePassword("abc"), enabled: true)
       def leader = new User(username: "leader", password: springSecurityService.encodePassword("abc"), enabled: true)
       def admin = new User(username: "admin", password: springSecurityService.encodePassword("abc"), enabled: true)

       println "Now joining users and their roles"
       UserRole.create(user, userRole)  <------------- FAILING HERE
       UserRole.create(leader, leaderRole)
       UserRole.create(admin, adminRole)
       println "All Done Creating users & roles"
具体内容如下:

BootStrap.groovy第168行:
UserRole.create(user,UserRole)


UserRole.groovy第32行:
新建用户角色(用户:用户,角色:角色)。保存(刷新:刷新,插入:真)
您永远不会保存新用户

user.save()
leader.save()
admin.save()

太棒了,谢谢你,格雷格。在教程中,他将新的用户类与现有的用户类集成在一起,我没有注意到他在其中有一个保存。
user.save()
leader.save()
admin.save()