【发布时间】:2015-01-06 19:19:45
【问题描述】:
我无法在 Windows 8.1 和 Centos 7 上保存 grails 中的域对象。每当我尝试创建一个空域类并将其保存在 BootStrap.groovy 中时,运行应用程序后我总是收到相同的错误消息:
Error |
2014-11-10 14:53:44,225 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the appl
ication: Method on class [com.test.Book] was used outside of a Grails application. If running in the context of a test
using the mocking API or bootstrap Grails correctly.
Message: Method on class [com.test.Book] was used outside of a Grails application. If running in the context of a test
using the mocking API or bootstrap Grails correctly.
Line | Method
->> 5 | doCall in BootStrap$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 327 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 320 | executeForEnvironment . . . . . in ''
| 296 | executeForCurrentEnvironment in ''
| 262 | run . . . . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
| Error Forked Grails VM exited with error
我的域类:
package com.test
class Book {
String name
static constraints = {
}
}
BootStrap.groovy:
import com.test.Book
class BootStrap {
def init = { servletContext ->
new Book(name: "My Book").save()
}
def destroy = {
}
}
我尝试了 2.4.3 和 2.4.4 版本的 grails。我的 jdk 版本是 1.7.0_71(也试过 jdk6 和 jdk8)。有趣的是,我在 Ubuntu 和 OpenSuse 上尝试了确切的步骤,并且成功地保存了该对象。那么,可能是什么问题?
问候,
【问题讨论】:
-
Book.groovy是否在grails-app/domain/com/test/中定义?您是否使用默认的 Hibernate 插件(查看BuildConfig.groovy)? -
我已经使用 create-domain-class 命令创建了域类,因此我在 grails-app/domain/com/test 文件夹中有 Book.groovy 文件。我正在使用默认的休眠插件,即:hibernate4:4.3.6.1。
-
此应用程序是否经历了从旧版本 Grails 升级的路径?如果您的某些代码是使用旧版本的 Grails 编译的,则可能会发生这种情况(取决于许多其他因素)。如果不确定,请验证运行
grails clean后问题是否仍然存在。 -
问题是,我在一个新项目中收到该错误消息。简单地说,我正在创建一个新项目并创建一个空域类。当我尝试将其保存在 BootStrap 中时,它失败了。
-
我不知道可能出了什么问题。如果您在 jira.grails.org/browse/GRAILS 提交 JIRA 并附上详细信息,我们将进行查看。很抱歉给您带来麻烦。
标签: grails grails-orm grails-domain-class bootstrapping