grails外壳和闭包

grails外壳和闭包,grails,groovy,Grails,Groovy,正在尝试在grails控制台中运行以下命令: Family.where() {password =~ "%qw%"} 对存储对象的非常简单的查询。我回来了: ERROR groovy.lang.MissingMethodException: No signature of method: com.babyboom.Family.where() is applicable for argument types: (groovysh_evaluate$_run_closure1) valu

正在尝试在grails控制台中运行以下命令:

Family.where() {password =~ "%qw%"}
对存储对象的非常简单的查询。我回来了:

    ERROR groovy.lang.MissingMethodException:
No signature of method: com.babyboom.Family.where() is applicable for argument types: (groovysh_evaluate$_run_closure1) values: [groovysh_evaluate$_run_closure1@34356294]
Possible solutions: where(groovy.lang.Closure), merge(), every(), grep(), merge(com.babyboom.Family), merge(java.util.Map)
我知道我创建的闭包与预期的不同。 两个问题:


  • 为什么有两种类型的闭包
  • Found尝试了它,但没有帮助,仍然得到相同的错误
  • 它在使用grails控制台时运行良好

这可能是grails shell的类加载器错误。要复制,请将依赖项添加到BuildConfig.gradle:

runtime "org.grails:grails-datastore-simple:3.1.2.RELEASE"
然后跑

import org.grails.datastore.mapping.simple.SimpleMapDatastore
import org.grails.datastore.gorm.GormStaticApi
class Bar {}

class Foo extends GormStaticApi<Bar> {
    Foo() {
        super(Bar, new SimpleMapDatastore(), [], null)
    }
}

def f = new Foo()
在grails中,壳产量:

groovy:000> def f = new Foo()
ERROR java.lang.LinkageError:
loader constraint violation: when resolving overridden method "Foo.$getStaticMetaClass()Lgroovy/lang/MetaClass;" the class loader (instance of groovy/lang/GroovyClassLoader$InnerLoader) of the current class, Foo, and its superclass loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader), have different Class objects for the type ()Lgroovy/lang/MetaClass; used in the signature

com.babyboom.Family
是域类吗?“为什么有两种类型的闭包?”-没有两种类型的闭包。我不知道你为什么会这样认为,我也不知道你所说的“我知道我创建的闭包与预期的不同。”“使用GroovyConsole时效果很好”-为了使该查询在groovy控制台中工作,您必须以某种方式在该控制台中引导Grails环境,这需要相当多的工作。你就是这么做的吗?com.babyboom.Family是域类吗是的,当从我的项目目录运行grails控制台时,所有内容都会自动启动,错误消息中缺少的关键字static是由于GormStaticApi.methodMissing()在没有isStatic标志的情况下引发MissingMethodException,这本身就是一个很小的错误。首先要正确地报告这个错误。您的症状(MissinMethodException)也很容易再现。我不知道现在是否有解决办法。
groovy:000> def f = new Foo()
ERROR java.lang.LinkageError:
loader constraint violation: when resolving overridden method "Foo.$getStaticMetaClass()Lgroovy/lang/MetaClass;" the class loader (instance of groovy/lang/GroovyClassLoader$InnerLoader) of the current class, Foo, and its superclass loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader), have different Class objects for the type ()Lgroovy/lang/MetaClass; used in the signature