spring java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15989325/
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 05:52:23  来源:igfitidea点击:

java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext

eclipsespringjsf-2tomcat6

提问by hela

I've faced problems for deploying my project which I use jsf/spring/hibernate as a faramework, I added the necessary jars specially org.springframework.web-3.1.0.CI-1162, The error is:

我在部署我的项目时遇到了问题,我使用 jsf/spring/hibernate 作为faramework,我特别添加了必要的 jars org.springframework.web-3.1.0.CI-1162,错误是:

SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4150)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

and the list of jars added:

并添加了罐子列表:

antlr-2.7.6.jar

antlr-2.7.6.jar

commons-dbcb-1.4.jar

commons-dbcb-1.4.jar

commons-collections-3.1.jar

commons-collections-3.1.jar

commons-pool.1.6.jar

commons-pool.1.6.jar

commons-logging-1.1.jar

commons-logging-1.1.jar

dom4j-1.6.1.jar

dom4j-1.6.1.jar

hibernate3.jar

hibernate3.jar

hibernate-jpa-2.0-api-1.0.1.Final.jar

hibernate-jpa-2.0-api-1.0.1.Final.jar

iText-5.0.4.jar (For Primefaces)

iText-5.0.4.jar(用于 Primefaces)

javassist-3.9.0.GA.jar

javassist-3.9.0.GA.jar

com.springsource.org.jboss-el-2.0.0.GA.jar (Optional for running on Tomcat 6)

com.springsource.org.jboss-el-2.0.0.GA.jar(可选用于在Tomcat 6上运行)

jsf-api.jar (Mojarra 2.0.4)

jsf-api.jar (Mojarra 2.0.4)

jsf-impl.jar (Mojarra 2.04)

jsf-impl.jar (Mojarra 2.04)

jta-1.1.jar

jta-1.1.jar

log4j-1.2.11.jar

log4j-1.2.11.jar

mysql-connector-java-5.0.5.jar (For MySQL)

mysql-connector-java-5.0.5.jar(用于 MySQL)

org.springframework.aop-3.1.0.CI-1162.jar

org.springframework.aop-3.1.0.CI-1162.jar

org.springframework.asm-3.1.0.CI-1162.jar

org.springframework.asm-3.1.0.CI-1162.jar

org.springframework.aspects-3.1.0.CI-1162.jar

org.springframework.aspects-3.1.0.CI-1162.jar

org.springframework.beans-3.1.0.CI-1162.jar

org.springframework.beans-3.1.0.CI-1162.jar

org.springframework.context-3.1.0.CI-1162.jar

org.springframework.context-3.1.0.CI-1162.jar

org.springframework.context.support-3.1.0.CI-1162.jar

org.springframework.context.support-3.1.0.CI-1162.jar

org.springframework.core-3.1.0.CI-1162.jar

org.springframework.core-3.1.0.CI-1162.jar

org.springframework.expression-3.1.0.CI-1162.jar

org.springframework.expression-3.1.0.CI-1162.jar

org.springframework.jdbc-3.1.0.CI-1162.jar

org.springframework.jdbc-3.1.0.CI-1162.jar

org.springframework.orm-3.1.0.CI-1162.jar

org.springframework.orm-3.1.0.CI-1162.jar

org.springframework.oxm-3.1.0.M1.jar

org.springframework.oxm-3.1.0.M1.jar

org.springframework.transaction-3.1.0.CI-1162.jar

org.springframework.transaction-3.1.0.CI-1162.jar

org.springframework.web-3.1.0.CI-1162.jar

org.springframework.web-3.1.0.CI-1162.jar

org.springframework.web.portlet-3.1.0.M1.jar

org.springframework.web.portlet-3.1.0.M1.jar

org.springframework.web.servlet-3.1.0.CI-1162.jar

org.springframework.web.servlet-3.1.0.CI-1162.jar

poi-3.2-FINAL-20081019.jar (For Primefaces)

poi-3.2-FINAL-20081019.jar(用于 Primefaces)

primefaces-3.5jar

primefaces-3.5jar

slf4j-api-1.6.1.jar

slf4j-api-1.6.1.jar

slf4j-jdk14-1.6.1.jar

slf4j-jdk14-1.6.1.jar

qlfj4-log4j12-1.6.4.jar

qlfj4-log4j12-1.6.4.jar

回答by KingFeming

For this error, there can be different solutions. I have noted down the ones that had worked for me.

对于此错误,可以有不同的解决方案。我已经记下了对我有用的那些。

Solution 1.This is always happened in deployment and debugging environment. In deployment environment, just make sure your server classpath has included the Spring jar library (e.g spring-4.0.4.jar).

解决方案 1.在部署和调试环境中经常出现这种情况。在部署环境中,只需确保您的服务器类路径已包含 Spring jar 库(例如 spring-4.0.4.jar)。

In debugging environment, the steps may vary from different IDE, but the solution is same. In Eclipse, developers usually will create a tomcat, jboss…whatever application server for debugging, just make sure the correct Spring jars are included.

在调试环境中,不同IDE的步骤可能有所不同,但解决方法是一样的。在 Eclipse 中,开发人员通常会创建一个 tomcat、jboss……任何用于调试的应用程序服务器,只要确保包含正确的 Spring jar 即可。

  1. Double click on your debugging server
  2. Click on the “Open launch configuration” to access the server environment
  3. Click on the classpath tab
  4. Include the Spring jar file here , it may also required common log jar due to Spring dependency.
  5. Done, run your application again.
  1. 双击您的调试服务器
  2. 点击“打开启动配置”访问服务器环境
  3. 单击类路径选项卡
  4. 在此处包含 Spring jar 文件,由于 Spring 依赖,它可能还需要通用日志 jar。
  5. 完成,再次运行您的应用程序。

.

.

Solution 2.If you are using Maven as a build tool and downloading dependencies using it, there can be some jar conflict. Because Tomcat servers normally provide some jars such as servlet-api and jpa-api. So if you again included them using maven; there will be problems in identifying them.

解决方案 2.如果您使用 Maven 作为构建工具并使用它下载依赖项,则可能存在一些 jar 冲突。因为Tomcat服务器一般都会提供servlet-api、jpa-api等一些jar包。因此,如果您再次使用 maven 包含它们;识别它们会有问题。

Solution 3.If you are using Eclipse as your IDE and using Maven as your build tool and tomcat as your server; remember Tomcat server will not look on the jars which are just inside the folders. For that there's a small trick,

解决方案 3.如果您使用 Eclipse 作为您的 IDE,并使用 Maven 作为您的构建工具和 tomcat 作为您的服务器;请记住,Tomcat 服务器不会查看文件夹中的 jar。为此,有一个小技巧,

  1. Right click on your projectand select properties
  2. From the displayed window, select Deployment Assembly
  3. Select Add
  4. Add Maven dependencies
  5. Click Applyand Click OK
  1. 右键单击您的项目并选择属性
  2. 从显示的窗口中,选择部署程序集
  3. 选择添加
  4. 添加Maven依赖
  5. 单击应用并单击确定

Hope one of these solutions would help you to solve your problem. Happy Coding and make sure that is using Java.

希望这些解决方案之一可以帮助您解决问题。快乐编码并确保使用 Java。

回答by Mariuszy

In my situation, I use maven to build the project, just because the war file is not created correctly, it will leads to this exception. I check the war file and run install again, that solve my problem.

在我的情况下,我使用maven构建项目,只是因为war文件没有正确创建,会导致这个异常。我检查了war文件并再次运行安装,这解决了我的问题。

回答by xuhaojin

I use eclipse and find that there is no maven dependencies config on Deployment Assembly, so I modified .classpath from

我用eclipse发现Deployment Assembly上没有maven依赖配置,所以修改了.classpath from

     <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
       <attributes>
            <attribute name="maven.pomderived" value="true"/>
       </attributes>
     </classpathentry>

to

     <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
       <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
       </attributes>
     </classpathentry>

回答by olyanren

You have to download necessary jar file. You can download spring-context.jar file from the following link

您必须下载必要的 jar 文件。您可以从以下链接下载 spring-context.jar 文件

http://mvnrepository.com/artifact/org.springframework/spring-context/3.2.2.RELEASE

http://mvnrepository.com/artifact/org.springframework/spring-context/3.2.2.RELEASE

回答by artbristol

I suggest you replace all the Spring jars with the most up to date version (3.2.2.RELEASE)

我建议您将所有 Spring jar 替换为最新版本 (3.2.2.RELEASE)

回答by proxy

Make sure your server classpath has included the Spring jar library. Watch this link.

确保您的服务器类路径已包含 Spring jar 库。观看此链接