【问题标题】:Grails console - Unable to find class?Grails 控制台 - 找不到类?
【发布时间】:2011-02-08 23:17:20
【问题描述】:

我正在阅读“Grails in Action”一书,但我一直停留在介绍 grails 控制台的那部分。在我的项目目录中,我输入“grails console”打开一个控制台窗口,控制台甚至输出信息表明它正在编译类,但是当我在控制台中输入这个时:

new Quote(author:'Larry Wall',content:'There is more than one method to our madness.').save()

我收到此错误:

unable to resolve class Quote 
 at line: 1, column: 1

Quote 类存在于grails-app/domain/qotd/Quote.groovy 的Quote.groovy 中,我无法运行上述命令。

这里出了什么问题?

【问题讨论】:

    标签: grails groovy


    【解决方案1】:

    在尝试实例化之前,您是否尝试过导入包含您的域类的包?

    import qotd.Quote
    new Quote(author:'Larry Wall',content:'There is more than one method to our madness.').save()
    

    确保您也可以尝试指定完整的限定名称:

    new qotd.Quote(author:'Larry Wall',content:'There is more than one method to our madness.').save()
    

    【讨论】:

    • 奇数。由于这本书没有提到它,我以为我得到了自动导入魔法,或者其他什么。
    • 这是 Grails In Action 的问题。在写这篇文章的时候,这行得通,但它随着后来的 grails 版本而改变了......
    • 我遇到了同样的问题,尽管按照这个答案的建议做了,但我仍然没有成功。还有其他想法吗?
    【解决方案2】:

    我正在浏览 Grails in Action 第二版 (2.1.1) 的 MEAP,发现运行解决方案:

    grails clean
    grails console
    

    再次在 groovy 控制台中输入代码并运行

    【讨论】:

      【解决方案3】:

      看起来从 Grails 工具上下文菜单中选择“刷新依赖项”也可以解决此类问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-18
        • 2011-01-14
        • 1970-01-01
        • 1970-01-01
        • 2021-06-09
        • 1970-01-01
        相关资源
        最近更新 更多