【问题标题】:Grails deployment using run-war throws exception使用 run-war 部署 Grails 会引发异常
【发布时间】:2015-03-22 03:40:29
【问题描述】:

环境:Windows 7、JDK1.7、GGTS 3.6.1,数据库:Postgres 9.3、Grails 2.4.3

与 run-app 一起使用时,系统似乎启动并运行良好。 当我使用 run-war 时,它会构建 war 文件,并在运行应用程序期间抛出异常,附在下面。 (java.lang.NoClassDefFoundError:无法初始化类 grails.util.Holders) 当我查看 buildconfig.groovy 并删除了我为该应用程序所需的 jar 文件的依赖项添加的几个条目时。这些罐子是我开发的,有产品特定的代码。一旦删除,系统就会启动,没有任何异常。 这些 jars 有 java 类文件(不是 groovy),这些是使用 JDK 1.7 开发的。 这些类文件在应用程序中使用(特定于产品) 已添加 postgres 数据库,而不是默认数据库。 依赖的 jars 是我们内部的 repo 的一部分。 为了确保应用程序没有问题,我创建了一个示例应用程序并尝试了 run-war;它似乎工作正常。当我在构建配置中添加这些依赖 jar 条目时,它开始抛出异常。 repo url 已在依赖 jar 的构建配置中使用

例外:

Error | SLF4J: Class path contains multiple SLF4J bindings.
Error | SLF4J: Found binding in [jar:file:/C:/software/grails-2.4.3/dist/grails-plugin-log4j-2.4.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Error | SLF4J: Found binding in [jar:file:/C:/<loc>/<applicationName>/target/work/tomcat/webapps/<applicationName>/WEB-INF/lib/grails-plugin-log4j-2.4.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Error | SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Error | SLF4J: Actual binding is of type [org.slf4j.impl.GrailsSlf4jLoggerFactory]
Error | log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
Error | log4j:WARN Please initialize the log4j system properly.
Error | log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class grails.util.Holders
Caused by: java.lang.NoClassDefFoundError: Could not initialize class grails.util.Holders
    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)
Error listenerStart
Context [/<applicationName>] startup failed due to previous errors
The web application [/<applicationName>] registered the JDBC driver [org.h2.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
The web application [/<applicationName>] registered the JDBC driver [org.postgresql.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

【问题讨论】:

    标签: grails


    【解决方案1】:

    NoClassDefFoundError 通常很难修复。它很容易与ClassNotFoundException 混淆,但它非常不同。如果你得到一个ClassNotFoundException,你就有了它试图加载但找不到的类的名称。这通常很容易修复 - 找到包含它的 jar,并为其添加依赖项,从它部署到的 Maven 存储库中解析它,然后重新开始工作。

    但是NoClassDefFoundError 发生在您尝试加载的类找不到它所依赖的类或资源时。知道类名通常不是很有帮助,这在这里肯定是正确的——Holders 是一个 Grails 类,它显然在你的类路径中。奇怪的是,它的所有依赖项当然也在类路径中,所以它可能在几个 jars 之外。

    但是由于您已手动将 jar 添加到 lib 目录,因此您很可能错过了其中一个的依赖项。查看您的导入并尝试找出缺少的内容。这可能是一件微不足道的事情,对你想做的事情并不重要。但是如果与它间接相关的类加载失败,则需要确保它存在。

    【讨论】:

    • 感谢您的建议,我尝试了以下方法;我运行了创建war文件的命令“grails dev war”,同样爆炸了。我运行命令“grails dependency-report”并手动验证项目所需的所有 jar 都可用。甚至间接需要的罐子(罐子需要的罐子)。 grails 系统如何在 run-app 期间而不是在 run-war 期间解决相同的问题?
    • 问题已解决。应用程序所需的 jar 使用 Spring 作为依赖项,这是一个不同的版本。所以类路径从 jar 中获取了 Spring 版本并搞砸了启动。
    猜你喜欢
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2015-09-04
    • 2010-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    相关资源
    最近更新 更多