的Grails版本上類[]的方法:2.3.4的Grails java.lang.IllegalStateException的:Grails應用程序之外使用
Hibernate插件:運行時 「:休眠:3.6.10.6」
線BootStrap.groovy中產生錯誤:
def adminRole = new Role(authority: 'ROLE_USER').save(flush: true)
事實上任何在任何類保存操作(控制器,BootStrap.groovy中)導致該錯誤。
但是,當我得到在另一臺計算機中創建的域類時,工作正常,沒有錯誤。
有什麼建議嗎?
謝謝。
完整堆棧跟蹤:
ERROR context.GrailsContextLoader Error initializing the application: Method on class [com.hib.Role] 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 [com.hib.Role] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
at BootStrap$_closure1.doCall(BootStrap.groovy:9)
at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:308)
at grails.util.Environment.executeForEnvironment(Environment.java:301)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:277)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
我不使用maven或嘲諷。
Botstrap.groovy
class BootStrap {
def init = { servletContext ->
def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
}
def destroy = {
}
}
你可以發佈你的'Bootstrap.groovy'嗎?聽起來你正在運行'init'關閉之外的一個閉包 –
我添加了Bootstrap.groovy。相關代碼位於init關閉內部。 – atahan
我認爲它與Windows 8有關。因爲在Mac OS X和Windows 7中沒有錯誤。 – atahan