的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