【发布时间】:2012-06-14 20:35:05
【问题描述】:
我正在尝试通过 Mongodb Morphia 插件 (v.0.7.8) 将 Mongodb 与 Grails 应用程序一起使用。我已经用 com.google.code.morphia.annotations.Entity Annotation 注释了一个域类(它是 not 在 grails-app/mongo 文件夹内):
import com.google.code.morphia.annotations.Entity
@Entity("Question")
class Question {
Integer order
String question
}
现在我正在尝试将新实体保存到控制器中的数据库中:
def index() {
def q = new Question()
}
q.save()
但这会引发 HTTP 500 错误:
java.lang.IllegalStateException
Method on class [Question] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
我做错了什么?
编辑:
我将我的域类移动到 grails-app/mongo 并删除了 @Entity 注释。现在错误消失了,但是数据库还是空的?
编辑2:
现在我明白了:
URI
/Survey/survey/index
Class
java.lang.NoSuchMethodException
Message
survey.Survey.<init>()
要么这个插件有严重的错误,要么它不像快速入门微示例所暗示的那样容易设置。再次:我做错了什么?
【问题讨论】: