grails - 贝壳和瓶盖

标签 grails groovy

尝试在grails console中运行以下命令:

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)

我知道我创建的关闭与预期的不同。
几个问题:
  • 为什么有两种类型的闭包?
  • 找到Why am I getting a "No signature of method"" error when running the closure recursion example in the Groovy shell?尝试了一下,但没有帮助,仍然出现相同的错误
  • 使用grails控制台时效果很好
  • 最佳答案

    这可能是带有grails shell 的classloader错误。要重现,请向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控制台中,产量:
    Result: Foo@699c0395
    

    在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
    

    关于grails - 贝壳和瓶盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25943957/

    相关文章:

    grails - 无法检查grails中的空数据

    image - 在grails中将图像保存到Web应用程序下的文件夹

    grails - Grails “deep”条件+一对多关系

    validation - Groovy/Grails : How are constraints implemented?

    java - 缓存键生成

    grails - 如何确定Grails域数组字段的类

    java - Grails - 项目构建系统

    grails - 在 Groovy 和 Grails 中使用枚举的正确方法

    java - 我可以使用 Grails 但使用 Java 编写代码吗?

    regex - 使用正则表达式和 OR 获取组