spring Apache Tomcat 设置 java.lang.NoClassDefFoundError: org/springframework/asm/ClassVisitor

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9268101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 04:56:07  来源:igfitidea点击:

Apache Tomcat Setup java.lang.NoClassDefFoundError: org/springframework/asm/ClassVisitor

springexceptiontomcat

提问by Martin Nielsen

I have just installed tomcat through the ubuntu package manager. I open the log and the first thing I see is an interesting exception.

我刚刚通过 ubuntu 包管理器安装了 tomcat。我打开日志,首先看到的是一个有趣的异常。

java.lang.NoClassDefFoundError: org/springframework/asm/ClassVisitor

java.lang.NoClassDefFoundError: org/springframework/asm/ClassVisitor

Am I missing something in the installation?

我在安装中遗漏了什么吗?

It should be said that the reason I reinstalled in the first place was that I was giving my first go at webservices using Tomcat, and that didn't work. But for now: Why am I getting this exception? I pasted the entire log out of kindness:

应该说,我重新安装的原因首先是我第一次尝试使用 Tomcat 的 web 服务,但没有成功。但是现在:为什么我会收到此异常?我出于善意粘贴了整个日志:

Feb 13, 2012 10:00:17 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Feb 13, 2012 10:00:17 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/asm/ClassVisitor
at org.springframework.context.support.AbstractRefreshableApplicationContext.customizeBeanFactory(AbstractRefreshableApplicationContext.java:218)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:740)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: org.springframework.asm.ClassVisitor
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1484)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1329)
... 31 more
Feb 13, 2012 10:00:17 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Feb 13, 2012 10:02:30 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Feb 13, 2012 10:02:30 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class     org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/asm/ClassVisitor
at org.springframework.context.support.AbstractRefreshableApplicationContext.customizeBeanFactory(AbstractRefreshableApplicationContext.java:218)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:740)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: org.springframework.asm.ClassVisitor
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1484)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1329)
... 31 more
Feb 13, 2012 10:02:30 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext

回答by Michael Righi

It looks like Tomcat is trying to deploy a web app that relies on Spring ASM but it can't find the JAR file for Spring ASM on the classpath. I'm not sure what version of Spring your web app is using, but the latest version (as of today) for that JAR file is 3.1.0.RELEASE.

看起来 Tomcat 正在尝试部署一个依赖 Spring ASM 的 Web 应用程序,但是它在类路径上找不到 Spring ASM 的 JAR 文件。我不确定您的 Web 应用程序使用的是哪个版本的 Spring,但该 JAR 文件的最新版本(截至今天)是 3.1.0.RELEASE。

If you're using Maven, you can add the missing JAR file to your project by adding this to your project's pom.xml:

如果您使用的是 Maven,则可以通过将以下内容添加到项目的 pom.xml 来将缺少的 JAR 文件添加到您的项目中:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.asm</artifactId>
    <version>3.1.0.RELEASE</version>
</dependency>

If you're not using Maven to manage your dependencies, then you can obtain org.springframework.asm-3.1.0.RELEASE.jar (or whichever version you need) by downloading the entire Spring Framework from http://www.springsource.org/spring-community-download. The ASM jar file will then need to be placed in your project's WEB-INF/lib folder.

如果您不使用 Maven 来管理您的依赖项,那么您可以通过从http://www.springsource下载整个 Spring Framework 来获取 org.springframework.asm-3.1.0.RELEASE.jar(或您需要的任何版本).org/spring-community-download。然后需要将 ASM jar 文件放在项目的 WEB-INF/lib 文件夹中。

回答by Anton

The common approach to handle this situation

处理这种情况的常用方法

1) establish what jar library contains missing classs.

1) 确定哪些 jar 库包含缺少的类。

2) check, that this jar presents in your classpath

2)检查,这个jar出现在你的类路径中

回答by Steer360

This error most possibly comes from the entries that you have in the web.xml. For example if you have this - org.springframework.web.servlet.DispatcherServlet. !! So when tomcat starts, load-on-startup tries to find out the spring asm context, but probably deployment assemblyis missing the maven dependency jar (although the jar is available) To resolve this try setting up the below

此错误很可能来自您在 web.xml 中的条目。例如,如果你有这个 - org.springframework.web.servlet.DispatcherServlet。!! 所以当 tomcat 启动时,load-on-startup 尝试找出 spring asm 上下文,但可能部署程序集缺少 maven 依赖 jar(虽然 jar 可用)要解决这个问题,请尝试设置以下

**Basiaclly In project options you should include Maven Dependencies to your Deployment Assembly** 

1.  Project properties-> Deployment Assembly -> Add.. 

2.  Java Build Path Entries -> Maven Dependencies 

3.  Finish

 Run mavem clean install and run on server. The error should go away.

回答by Steer360

In my case, the problem was in 2 versions of Java installed on computer: Java 7 and Java 8. Unisntalling Java 7 solved problem.

就我而言,问题出在计算机上安装的 2 个 Java 版本中:Java 7 和 Java 8。卸载 Java 7 解决了问题。