我正在执行简单的spring依赖注入程序&得到这个异常。 我已经包含了common-logging1.1.1.jar和spring.jar文件。你能帮我一下吗?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:119)
    at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:55)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:56)
    at com.client.StoryReader.main(StoryReader.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 6 more

当前回答

我遇到了同样的问题,只需将commons-logging.jar添加到类路径中就解决了这个问题。

其他回答

添加common -logging.jar或common -logging-1.1.jar将解决这个问题…

嘿,我在tutorialpoint.com上看教程。完成第2步后添加—安装Apache Common Logging API:你必须从这一步下载的文件中导入外部jar库到项目中。对我来说,这个文件的名称是“commons-logging-1.1.1”。

我也遇到过同样的问题,要解决这个问题,请从下面的url下载jar文件

http://commons.apache.org/logging/download_logging.cgi

并复制到您的lib文件夹,将解决您的问题。

我在eclipse IDE中也有同样的问题,我的解决方案是: 右键单击My project > Properties

单击Maven并在活动Maven项目中写入:jar

最后,应用并关闭

在我的例子中,我正在eclipse中测试Tomcat应用程序,并得到了这个错误。我通过检查.classpath文件解决了这个问题,并更正了下面的条目:

<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>

属性org.eclipse.jst.component.dependency已经丢失。