import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestSpringProject {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("SpringConfig.xml");
Restaraunt restaurantObj = (Restaraunt) context.getBean("restaurantBean");
restaurantObj.greetCustomer();
}
}
运行:
线程“main”中的异常java.lang.NoClassDefFoundError:org / apache / commons / logging / LogFactory 在org.springframework.context.support.AbstractApplicationContext。(AbstractApplicationContext.java:154) 在org.springframework.context.support.AbstractApplicationContext。(AbstractApplicationContext.java:215) 在org.springframework.context.support.AbstractRefreshableApplicationContext。(AbstractRefreshableApplicationContext.java:88) 在org.springframework.context.support.AbstractRefreshableConfigApplicationContext。(AbstractRefreshableConfigApplicationContext.java:58) 在org.springframework.context.support.AbstractXmlApplicationContext。(AbstractXmlApplicationContext.java:61) 在org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:136) 在org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:83) 在org.springcore.tutorials.TestSpringProject.main(TestSpringProject.java:8) 引起:java.lang.ClassNotFoundException:org.apache.commons.logging.LogFactory 在java.net.URLClassLoader $ 1.run(URLClassLoader.java:372) 在java.net.URLClassLoader $ 1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) 在java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ......还有8个 Java结果:1 建立成功(总时间:2秒)
答案 0 :(得分:0)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
JVM找不到公共日志记录类
将commons-logging.jar添加到类路径
答案 1 :(得分:0)
java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at
您的项目中需要apache commons logging jar。它无法解析项目中的LogFactory。