Grails在缺少GrailsMock类的tomcat上失败

时间:2013-03-04 17:24:22

标签: tomcat grails deployment dependencies

我在我的生产Ubuntu以及我在Tomcat 7上部署我的应用程序时在我的开发iOS上遇到了这个奇怪的失败。很奇怪......我找不到导致问题的确切代码片段/: 调用$ grails run-app工作得很好..

这是我的错误消息:

2013-03-04 16:47:27,966 [localhost-startStop-1] ERROR context.ContextLoader  - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/
applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Unable to locate constructor with Class p
arameter for class org.codehaus.groovy.grails.commons.DefaultGrailsControllerClass
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsC
ontrollerClass
        ... 6 more
Caused by: java.lang.reflect.InvocationTargetException
        ... 6 more
Caused by: java.lang.NoClassDefFoundError: grails/test/GrailsMock
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
        at java.lang.Class.getDeclaredMethods(Class.java:1808)
        ... 6 more
Caused by: java.lang.ClassNotFoundException: grails.test.GrailsMock
        ... 8 more
2013-03-04 16:47:27,991 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing the application: Error creating bean with na
me 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.
lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsControllerClass
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/
applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Unable to locate constructor with Class p
arameter for class org.codehaus.groovy.grails.commons.DefaultGrailsControllerClass
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsC
ontrollerClass
        ... 6 more
Caused by: java.lang.reflect.InvocationTargetException
        ... 6 more
Caused by: java.lang.NoClassDefFoundError: grails/test/GrailsMock
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
        at java.lang.Class.getDeclaredMethods(Class.java:1808)
        ... 6 more
Caused by: java.lang.ClassNotFoundException: grails.test.GrailsMock
        ... 8 more
2013-03-04 16:47:28,003 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing Grails: Error creating bean with name 'plugi
nManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.Runt
imeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsControllerClass
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/
applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Unable to locate constructor with Class p
arameter for class org.codehaus.groovy.grails.commons.DefaultGrailsControllerClass
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsC
ontrollerClass
        ... 6 more
Caused by: java.lang.reflect.InvocationTargetException
        ... 6 more
Caused by: java.lang.NoClassDefFoundError: grails/test/GrailsMock
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
        at java.lang.Class.getDeclaredMethods(Class.java:1808)
        ... 6 more
Caused by: java.lang.ClassNotFoundException: grails.test.GrailsMock
        ... 8 more

我的BuildConfig:

grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // specify dependency exclusions here; for example, uncomment this to disable ehcache:
        // excludes 'ehcache'
    }
    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve

    repositories {
        inherits true // Whether to inherit repository definitions from plugins

        grailsPlugins()
        grailsHome()
        grailsCentral()

        mavenLocal()
        mavenCentral()


        mavenRepo "http://repository.codehaus.org/"
        mavenRepo "http://repository.jboss.org/maven2/"

        // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
        //mavenRepo "http://snapshots.repository.codehaus.org"
        //mavenRepo "http://repository.codehaus.org"
        //mavenRepo "http://download.java.net/maven/2/"
        //mavenRepo "http://repository.jboss.com/maven2/"
    }
    dependencies {
        compile 'com.googlecode.json-simple:json-simple:1.1'
        compile 'org.mongodb:mongo-java-driver:2.10.1'
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

        // runtime 'mysql:mysql-connector-java:5.1.20'
    }

    plugins {
        compile ":mongodb:1.0.0.GA"
        build ":tomcat:$grailsVersion"
        runtime(":hibernate:$grailsVersion") {
            export = false
        }
        test ":build-test-data:2.0.3"
        compile ":crypto:2.0"
    }
}

谢谢,

阿米特。

PS:在grails-users列表中链接到我的问题:http://grails.1312388.n4.nabble.com/Grails-fails-on-tomcat-with-missing-class-GrailsMock-tt4642038.html

2 个答案:

答案 0 :(得分:1)

问题是我在我的一个服务的顶部引用了@Mock注释。 @Mock注释显然不属于那里,而是属于测试类。这创建了对Grails测试包的引用,无法从.war包解析。

我可能在做TDD /时将它混合起来:

答案 1 :(得分:0)

缺少的类是grails-test-2.1.1.jar(为您的版本调整2.1.1)。

请确保您部署了该jar文件。

或者,您可以使用Grails Console插件检查类路径。