【问题标题】:Can't run Grails app?无法运行 Grails 应用程序?
【发布时间】:2012-11-30 13:40:46
【问题描述】:

当我尝试运行我的 grails 应用程序时,出现以下错误:

Error 2012-11-30 15:35:57,948 [localhost-startStop-1] ERROR context.ContextLoader  - Context initialization failed
Message: 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 parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsServiceClass
   Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   680 | run . .  in java.lang.Thread
Caused by RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsServiceClass
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   680 | run . .  in java.lang.Thread
Caused by InvocationTargetException: null
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   680 | run . .  in java.lang.Thread
Caused by NoClassDefFoundError: com/lp/labs/scconnector/GitConnector
->> 2427 | privateGetDeclaredMethods in java.lang.Class
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1791 | getDeclaredMethods in     ''
|   303 | innerRun in java.util.concurrent.FutureTask$Sync
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   680 | run . .  in java.lang.Thread
Caused by ClassNotFoundException: com.lp.labs.scconnector.GitConnector
->> 202 | run      in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   190 | findClass in java.net.URLClassLoader
|   306 | loadClass in java.lang.ClassLoader
|   247 | loadClass in     ''
|   2427 | privateGetDeclaredMethods in java.lang.Class
|   1791 | getDeclaredMethods in     ''
|   303 | innerRun in java.util.concurrent.FutureTask$Sync
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   680 | run . .  in java.lang.Thread
| Error 2012-11-30 15:35:58,068 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error executing bootstraps: 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 parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsServiceClass
Message: 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 parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsServiceClass
   Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   680 | run . .  in java.lang.Thread
Caused by RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsServiceClass
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   680 | run . .  in java.lang.Thread
Caused by InvocationTargetException: null
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   680 | run . .  in java.lang.Thread
Caused by NoClassDefFoundError: com/lp/labs/scconnector/GitConnector
->> 2427 | privateGetDeclaredMethods in java.lang.Class
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1791 | getDeclaredMethods in     ''
|   303 | innerRun in java.util.concurrent.FutureTask$Sync
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   680 | run . .  in java.lang.Thread
Caused by ClassNotFoundException: com.lp.labs.scconnector.GitConnector
    ->> 202 | run      in java.net.URLClassLoader$1
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |   190 | findClass in java.net.URLClassLoader
    |   306 | loadClass in java.lang.ClassLoader
    |   247 | loadClass in     ''
    |   2427 | privateGetDeclaredMethods in java.lang.Class
    |   1791 | getDeclaredMethods in     ''
    |   303 | innerRun in java.util.concurrent.FutureTask$Sync
    |   138 | run      in java.util.concurrent.FutureTask
    |   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
    |   908 | run      in     ''

^   680 | run . .  in java.lang.Thread

这是我的 build.config 文件:

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 "warn" // 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()

        // 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 {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

        // runtime 'mysql:mysql-connector-java:5.1.20'
        compile 'org.eclipse.jgit:org.eclipse.jgit:2.0.0.201206130900-r'
        compile 'SC-Connector:SC-Connector:1.0'
        compile 'AccountConnector:AccountConnector:1.0'


        // runtime
        runtime 'org.springframework.ws:spring-xml:2.0.4.RELEASE'
        runtime 'org.springframework.ws:spring-ws-core:2.0.4.RELEASE'
        runtime 'com.thoughtworks.xstream:xstream:1.4.2'
        runtime 'org.springframework.ws:spring-oxm:3.1.0.RELEASE'
        runtime 'org.springframework.ws:spring-oxm-tiger:1.5.10'
        runtime 'com.sun.xml.bind:jaxb-impl:2.1.12'
        runtime 'javax.xml.bind:jaxb-api:2.1'
        runtime 'com.google.guava:guava:13.0.1'
        runtime 'xmlpull:xmlpull:1.1.3.1'

    }

    plugins {
        runtime ":hibernate:$grailsVersion"
        runtime ":jquery:1.7.2"
        runtime ":resources:1.1.6"

        build ":tomcat:$grailsVersion"

        runtime ":database-migration:1.1"

        compile ':cache:1.0.0'
    }
}

我认为这些类在我的类路径上,所以我不认为这是一个类路径问题。有人知道如何解决吗?

谢谢,

【问题讨论】:

  • 请提供更多信息。什么是grails版本?这是一个新鲜的项目?您是否已经尝试过grails cleangrails compile
  • grails 版本是 2.1.1。我将此项目复制到另一台机器上,它正在工作。我尝试清理并再次运行该项目,但仍然显示相同的错误。
  • 你能发布你的 buildConfig 吗? com.lp.labs.scconnector.GitConnector 是私人课程吗?我对此一无所知。
  • 正如@burt 回答的那样,这与您在 lib 文件夹中的 jar 相关。 grails run-war 有效吗?
  • 我得到:错误异常发生触发事件 [CreateWarStart]:grails-app/migrations 不存在。

标签: grails


【解决方案1】:

com.lp.labs.scconnector.GitConnector 是否在 lib 目录下的 jar 文件中?如果是这样,请运行 grails compile --refresh-dependencies 让 Grails 将其添加到类路径中

【讨论】:

  • 是的,它位于 lib 文件夹中的 jar 文件中。我运行这个命令,没有任何改变
  • 您是从命令行还是从 IDE 运行的?要在 STS 中识别它,您需要运行 Grails Tools|Refresh Dependencies 以使 STS 与 Grails 类路径同步。
  • 实际上,仔细观察你会得到一个NoClassDefFoundError,它与ClassNotFoundException 不同,因为这意味着该类存在,但它所依赖的类不存在。您是否缺少其他依赖项?
【解决方案2】:

也许您的问题可能源于其他原因,我遇到了同样的错误,在到处咨询后,我建议制作一个 Grails-CLEAN 并且一切都解决了。

【讨论】:

    【解决方案3】:

    使用命令

    grails clean-all
    

    之后使用:

    grails refresh-dependencies
    grails-compile
    

    比运行

    grails run-app
    

    【讨论】:

      猜你喜欢
      • 2013-11-03
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 1970-01-01
      • 2010-09-28
      相关资源
      最近更新 更多