将Grails 2.5应用程序部署到Tomcat8

时间:2015-07-25 13:23:23

标签: tomcat grails

我正在尝试将Grails v2.5.0应用程序部署到Tomcat 8.0.22并收到以下错误:

2015-07-25 13:11:09,714 ERROR [GrailsContextLoaderListener] - Error initializing Grails: 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:
net/sf/cglib/proxy/UndeclaredThrowableException
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:
net/sf/cglib/proxy/UndeclaredThrowableException     at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)     at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745) Caused by:
java.lang.NoClassDefFoundError:
net/sf/cglib/proxy/UndeclaredThrowableException     at
java.lang.Class.forName(Class.java:348)     ... 5 more Caused by:
java.lang.ClassNotFoundException:
net.sf.cglib.proxy.UndeclaredThrowableException     ... 6 more
25-Jul-2015 13:11:09.715 SEVERE [wwww startStop-1]
org.apache.catalina.core.StandardContext.listenerStart 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:
net/sf/cglib/proxy/UndeclaredThrowableException     at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)     at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745) Caused by:
java.lang.NoClassDefFoundError:
net/sf/cglib/proxy/UndeclaredThrowableException     at
java.lang.Class.forName(Class.java:348)     ... 5 more Caused by:
java.lang.ClassNotFoundException:
net.sf.cglib.proxy.UndeclaredThrowableException     ... 6 more
之后已将

net/sf/cglib添加到tomcat8共享库文件夹中,但它只导致net/sf/cglib/proxy/UndeclaredThrowableException 从未在开发模式中遇到过。

1 个答案:

答案 0 :(得分:0)

这只有两个原因。第一个是,你的WAR包含两个版本的jars用于所需的库cglib,第二个是你的WAR根本不包含这个库。

http://mvnrepository.com/artifact/cglib/cglib/3.1

由于以上任何原因,您将始终获得NoClassDefFoundError。但是,你可以轻松解决这个问题。将WAR文件部署到Tomcat时,将解压缩WAR文件,然后将ls解压缩到爆炸的WAR lib文件夹中:ls -al $CATALINA_HOME/webapps/ROOT/WEB-INF/lib/并查找名为cglib-*.jar的jar文件。

现在,如上所述,可能有两种可能性,或者没有名称为cglib的jar文件可用,或者将有两个名称为cglib且有两个不同版本的jar。

针对第一种情况的解决方案,您可以在BuildConfig.groovy中添加依赖项,例如:compile 'cglib:cglib:2.2.2'

对于第二种情况,您可以使用grails dependency-report查看该库是如何复制的,并且可以排除

注意:第二步,如果您想立即修复,只需从我指定的位置删除jar之一,然后重新启动Tomcat。