我正在尝试通过 Mongodb Morphia Plugin (v.0.7.8) 将 Mongodb 与 Grails 应用程序一起使用。我用 com.google.code.morphia.annotations.Entity 注释注释了一个域类(不在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>()
要么这个插件有严重的错误,要么它不像快速入门微示例所暗示的那样容易设置。再次:我做错了什么?