将我的 grails 应用程序从 grails 2.2.4 升级到 grails 2.3.1 后,test-app
构建在应用程序引导时失败,并显示以下错误消息:
Fatal error running tests: Method on class [de.javandry.minigolf.webapp.Role] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
运行构建,--stacktrace --verbose
我看到以下详细信息(堆栈跟踪减少到恕我直言相关行):
2013-10-25 22:56:27,876 [main] WARN util.DTDEntityResolver - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2013-10-25 22:56:28,674 [main] WARN hibernate.AbstractEhcacheRegionFactory - Couldn't find a specific ehcache configuration for cache named [de.javandry.minigolf.webapp.Role]; using defaults.
2013-10-25 22:56:32,264 [main] WARN servlet.DefaultGrailsApplicationAttributes - ApplicationContext not found in org.codehaus.groovy.grails.APPLICATION_CONTEXT attribute of servlet context.
| Error 2013-10-25 22:56:34,473 [main] ERROR plugins.DefaultGrailsPluginManager - Error configuring dynamic methods for plugin [hibernate:3.6.10.M3]: org.grails.datastore.gorm.GormStaticApi.setTransactionManager(Lorg/springframework/transaction/PlatformTransactionManager;)V
java.lang.NoSuchMethodError: org.grails.datastore.gorm.GormStaticApi.setTransactionManager(Lorg/springframework/transaction/PlatformTransactionManager;)V
at org.codehaus.groovy.grails.orm.hibernate.HibernateGormStaticApi.<init>(HibernateGormStaticApi.groovy:67)
at org.codehaus.groovy.grails.orm.hibernate.HibernateGormEnhancer.getStaticApi(HibernateGormEnhancer.groovy:87)
...
at grails.plugin.hibernate3.HibernatePluginSupport$__clinit__closure3.doCall(HibernatePluginSupport.groovy:444)
...
| Error Fatal error running tests: Method on class [de.javandry.minigolf.webapp.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 [de.javandry.minigolf.webapp.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 de.javandry.minigolf.webapp.Role.currentGormInstanceApi(Role.groovy)
at de.javandry.minigolf.webapp.Role$currentGormInstanceApi$0.call(Unknown Source)
...
at de.javandry.minigolf.webapp.Role.save(Role.groovy)
at de.javandry.minigolf.webapp.Role$save.call(Unknown Source)
...
at BootStrap$_closure1.doCall(BootStrap.groovy:7)
我的BootStrap.groovy
样子如下:
class BootStrap {
def init = { servletContext ->
def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true, failOnError: true)
def userRole = new Role(authority: 'ROLE_USER').save(flush: true, failOnError: true)
...
创建第一个实体时,错误发生在第 3 行。
[编辑] 我已经调整了插件和依赖项。这是我的部分BuildConfig.groovy
:
def seleniumVersion = "2.21.0"
def gebVersion = "0.9.0"
dependencies {
test("org.seleniumhq.selenium:selenium-htmlunit-driver:$seleniumVersion") {
exclude "xml-apis"
}
test "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
test "org.gebish:geb-spock:$gebVersion"
}
plugins {
runtime ":hibernate:3.6.10.M3"
runtime ":jquery:1.10.2"
runtime ":resources:1.2.1"
runtime ":database-migration:1.3.6"
build ":tomcat:7.0.40.1"
compile ":cache:1.1.1"
compile ":spring-security-core:1.2.7.3"
compile ":webxml:1.4.1"
test ":geb:$gebVersion"
test ":build-test-data:2.0.6"
}
我还能尝试什么来解决这个错误?