无法使用Spring Framework运行应用程序

时间:2013-05-19 08:23:45

标签: java spring

我定义了一个看起来像这样的简单类

public class Spring1 {
    public static void main(String[] args) {
        ApplicationContext context = new  ClassPathXmlApplicationContext("spring.xml");

     }
}

我的配置文件是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

</beans>

当我运行应用程序时,它显示以下错误

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:164)
at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:89)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:58)
at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at project.on.spring.Spring1.main(Spring1.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 7 more

请在我犯错的地方帮助我。

3 个答案:

答案 0 :(得分:2)

我认为你还没有包含“apache commons logging jar”。 Download并将其添加到您的项目中

答案 1 :(得分:2)

Donwload commons-logging并将jar放在WEB-INF / lib.Spring框架中,附带了很多库。确保在课程路径中添加了所有必需的内容。

对于未来 - 谷歌未找到的类名称,看它属于哪个库,下载并将其放在类路径上。

答案 2 :(得分:-1)

org.apache.commons.logging.LogFactory与您的Spring版本不兼容。

下载JAR