【发布时间】:2016-03-21 11:32:42
【问题描述】:
我正在使用 grails 应用程序。我想执行get(),save(),delete(),findBy() 等方法并与 grails 应用程序的域相关联。当我在 Utils 或 src/groovy 包中执行 Domain.get() 方法时,出现以下错误。
Caught: java.lang.IllegalStateException: Method on class [Domain Class] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
java.lang.IllegalStateException: Method on class [Domain Class] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
任何人都可以帮助我如何在 Utils 或 src/groovy 类中使用域类方法?
【问题讨论】:
-
您需要为您的问题提供更多背景信息。你在哪里使用
src/groovy中的课程?是什么在调用它们,进而调用您的域类?尝试为您的问题提供更多详细信息,并提供您正在做的实际示例,您会得到更好的答案。 -
import com.chatportal.ShiroUser class ChatUtility { static main(args) { def chatUtility = new ChatUtility() chatUtility?.display(1) } def display(def id){ println "ChatUtility 聊天用户:"+ShiroUser.get(id) } }
-
错误是发生在测试中还是正在运行的应用程序中?
-
@Piyush 你能指出这个错误是在什么情况下发生的吗?它发生在测试期间吗?如果没有,报告错误的域 lass 是否有什么特别之处(用 Java 编写?从插件中提取?映射到 hibernate cfg 文件中?有什么非标准的吗?)
-
如果没有更多上下文,您所询问的场景并不十分清楚。
标签: java grails grails-orm grails-2.0 grails-domain-class