在grails中保存域对象

时间:2014-11-10 13:09:43

标签: grails gorm grails-domain-class bootstrapping

我无法在 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的确切步骤,我设法保存对象没有问题。那么,问题可能是什么呢?

此致

1 个答案:

答案 0 :(得分:0)

问题解决了。似乎grails在操作系统的语言包方面存在问题。我使用的是Windows和Centos的土耳其语语言包。现在我已将其更改为英语,问题就解决了。