从Grails3.2升级到Grails3.3,不推荐使用GrailDomainClass Api

从Grails3.2升级到Grails3.3,不推荐使用GrailDomainClass Api,grails,grails-plugin,grails-3.3,Grails,Grails Plugin,Grails 3.3,为了将我的应用程序和插件升级到Grails3.3,我做了以下替换。(变量名称的更改是为了提高替换的清晰度。) Grails 3.2: Class<?> clazz = grailsDomainClass.clazz ... def grailsDomainClass = new DefaultGrailsDomainClass(clazz) ... GrailsDomainClassProperty[] properties = grailsDomainClass.propert

为了将我的应用程序和插件升级到Grails3.3,我做了以下替换。(变量名称的更改是为了提高替换的清晰度。)

Grails 3.2:

Class<?> clazz = grailsDomainClass.clazz
...

def grailsDomainClass = new DefaultGrailsDomainClass(clazz)
...

GrailsDomainClassProperty[] properties = grailsDomainClass.properties
...

def propertyName = grailsDomainClass.propertyName
...

def referenceType = grailsDomainClassProperty.referencedPropertyType
...
  • 我应该将
    doWithSpring
    中的代码放在我的插件的哪里

  • 手册页上说:

    解决方案是将上下文可用之前执行的任何逻辑移动到上下文可用之后执行的其他地方

    你在别的什么地方?是否有
    doWithContext
    closure?它可以用来注射豆子吗

  • 使用
    ClassPropertyFetcher.getPropertyValue
    方法

  • doWithApplicationContext
    是一种可以覆盖插件的方法,您可以在其中放置逻辑


  • 在grails数据存储6.0.9
    org.grails.datastore.mapping.reflect.ClassPropertyFetcher
    中,可以返回非静态属性值。但在6.1.6中,只能提取静态特性值。什么改变了?
    Class<?> clazz = persistentEntity.javaClass
    ...
    
    def persistentEntity = grailsApplication.mappingContext.getPersistentEntity(DomainClass.class.name)
    ...
    
    PersistentProperty[] properties = persistentEntity.persistentProperties
    ...
    
    def propertyName = persistentEntity.decapitalizedName
    ...
    
    def referenceType = persistentProperty.type
    
    grailsDomainClass.getPropertyValue(propertyName)