gpt4 book ai didi

hibernate - 我的 Grails 3.3.8 应用程序中 SpringSecurityService 中的 MissingPropertyException

转载 作者:行者123 更新时间:2023-12-02 14:48:29 24 4
gpt4 key购买 nike

使用 grails spring security plugin (3.2.3) 我有一个应用程序,其中包含使用本指南创建的标准域类:

https://grails-plugins.github.io/grails-spring-security-core/3.2.x/index.html#tutorials

它具有教程中指定的以下类:

Role.groovy、UserRole.groovy 和 User.groovy。

User.groovy 还添加了以下代码:

static belongsTo = [store: Store]

我还添加了两个额外的域类:

商店.groovy:
package com.mycompany.myapp

class Store {

String name

static constraints = {
}
}

书店.groovy:
package com.mycompany.myapp

class BookShop extends Store {

Boolean isOpen

static constraints = {
}
}

我在 Bootstrap.groovy 中创建了一个用户:
def init = {

def adminRole = new Role(authority: 'ROLE_ADMIN').save()

def testBookShop = new BookShop(name: "BookShop", isOpen: true).save()

def testUser = new User(username: 'me', password: 'password', store: testBookShop).save()

UserRole.create testUser, adminRole

UserRole.withSession {
it.flush()
it.clear()
}

assert User.count() == 1
assert Role.count() == 1
assert UserRole.count() == 1
}

我将我的 spring 安全服务注入(inject)我的 SecureController.groovy 并尝试呈现以下内容:
package com.mycompany.myapp

import grails.plugin.springsecurity.annotation.Secured

class SecureController {

def springSecurityService

@Secured('ROLE_ADMIN')
def index() {
def currentUser = springSecurityService.currentUser
render 'Store: ' + currentUser.store.name + ' is open = ' + currentUser.store.isOpen
}
}

我收到以下错误:
2018-09-10 20:34:26.068 ERROR --- [nio-8080-exec-2] 
o.g.web.errors.GrailsExceptionResolver : MissingPropertyException
occurred when processing request: [GET] /secure/index
No such property: isOpen for class: com.mycompany.myapp.BookShop

如果我专门打开商店,我可以让它工作:
render 'Store: ' + currentUser.store.name + ' is open = ' +
GrailsHibernateUtil.unwrapIfProxy(currentUser.store).isOpen

只是想知道是否有更好的解决方案来解决这个问题,我正在将一个大型应用程序从 grails 2.5.5 更新到 3.3.8,这在 2.5.5 中有效,我需要使用该方法更改大量代码以上,希望快速修复,谢谢。

最佳答案

该修复似乎正在将 GORM 从 6.1.9.RELEASE 升级到 6.1.10.RELEASE。在升级说明中没有看到任何表明这是一个已知错误的内容,因此无法评论 GORM 中的确切问题。

编辑:
此处记录的问题 - https://github.com/grails/grails-data-mapping/issues/1072

关于hibernate - 我的 Grails 3.3.8 应用程序中 SpringSecurityService 中的 MissingPropertyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52264523/

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