我在尝试在下面创建ApplicationContext的新实例时遇到类未找到异常。有什么我想念的吗?
package com.john;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Cook {
/**
* @param args
*/
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("/resources/test.xml");
Hamburger hamburger =(Hamburger)ctx.getBean("hamburger");
hamburger.addMeat();
}
}
汉堡课程:
package com.john;
public class Hamburger {
void addMeat() {
System.out.println("Meat is added");
}
}
我在src文件夹下的资源包中的test.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="hamburger" class="com.john.Hamburger"></bean>
</beans>
我得到的错误是:
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)
... 8 more