2014-01-29 37 views
0

的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 = { 
     } 
    } 
+0

你可以发布你的'Bootstrap.groovy'吗?听起来你正在运行'init'关闭之外的一个闭包 –

+0

我添加了Bootstrap.groovy。相关代码位于init关闭内部。 – atahan

+0

我认为它与Windows 8有关。因为在Mac OS X和Windows 7中没有错误。 – atahan

回答

0

我不得不使用Grails 2.3.6和Hibernate 3.6.10.8一个非常类似的错误。在运行集成测试时尝试在GORM对象上执行操作时出现。 最后,当我没有在datasource.groovy的'environments'的'test'部分创建数据源时,我在GORM域类的映射块中设置了一个数据源。排序和它的工作。

+2

你能解释一下吗?这个问题仅在项目从2.2.1升级到2.3.9后才出现? – user1859465

1

@ user3414639的提示帮助我。在我的情况下,代码由几个可以引入GORM对象的通用模块的项目组成。当一个GORM对象上的PostInsert事件触发了不同的GORM对象的保存(第二个GORM对象被映射到新的数据源)时,我看到了这个错误。

将新连接添加到项目的项目datasource.groovy的测试部分为我解决了错误。我将继续深入研究配置(不知道为什么GORM对象#1没有失败),但至少这让我走上了正确的轨道。

dataSource { 
} 
environments { 
    test { 
     dataSource_missing { 
      driverClassName = "com.mysql.jdbc.Driver" 
      url = "jdbc:mysql://localhost/testdomain?useUnicode=yes&characterEncoding=UTF-8" 
      username = "" 
      password = "" 
     } 
    } 
} 
相关问题