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

当前回答

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

其他回答

您只需下载commons-logging-1.1.2.jar,然后将该文件复制到lib中

终于,它起作用了。

如果你使用maven来管理依赖关系,在pom.xml中添加以下行:

<dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
</dependency>

如果你在Android上运行这个,那么注意显然是java。在Android上beans包不完整。尝试在Android上修复它,请尝试以下方法:

下载android-java-air-bridge.jar(目前下载按钮在页面底部或直接链接这里) 将下载的jar复制到你的[APPROOT]/app/libs目录(或以任何其他方式链接jar) 将import ***语句更改为air-bridge语句。例如导入javadz.beanutils.BeanUtils而不是导入org.apache.commons.beanutils.BeanUtils; 清理并重新构建项目

源1源2

我很抱歉,因为我意识到这并没有完全回答这个问题,尽管这个SO页面在搜索android生成的NoClassDefFoundError:失败的:beanUtils错误决议时出现了很多。

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

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