我正在执行简单的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

当前回答

尝试添加这个依赖项 org.apache.commons commons-exec 1.3

其他回答

在我的例子中,我正在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已经丢失。

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

添加common -logging.jar解决了这个问题

Imp文件包括:

antlr-runtime-3.0.1

org.springframework.aop-3.1.0.M2

org.springframework.asm-3.1.0.M2

org.springframework.aspects-3.1.0.M2

org.springframework.beans-3.1.0.M2

org.springframework.context.support-3.1.0.M2

org.springframework.context-3.1.0.M2

org.springframework.core-3.1.0.M2

org.springframework.expression-3.1.0.M2

commons-logging-1.1.1

至少有两种选择:

将common -logging jar文件复制到本地文件夹中,添加到您的文件中。

注意:链接jar可能会导致服务器出现问题,这可能是将它添加到构建路径但不能解决服务器启动问题的原因。

所以不要把罐子指向外部文件夹。

还是……

如果您真的不想在本地添加它,因为您在项目之间共享jar,那么……

如果您正在使用tc服务器实例,那么您需要将jar作为外部jar添加到服务器实例运行配置中。

去运行as,运行配置…,{你的tc服务器实例},然后是类路径选项卡。

然后添加common -logging jar。

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