我spring-framework-3.2.0.RELEASE
用来做一个简单的应用程序。但我得到 NoClassDefFoundError
这是我的代码
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
public class SpringDemo{
public static void main(String args[]) throws FileNotFoundException{
ApplicationContext context = new ClassPathXmlApplicationContext("message.xml");
}
}
class MessageClass{
private String message = null;
MessageClass(String message){
this.message = message;
}
public String getMessage(){
return message;
}
public void setMessage(String message){
this.message = message;
}
}
以下是我的message.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">
<bean id="message"
class="MessageClass">
<property name="message" value="Spring is fun." />
</bean>
我收到以下错误
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/c
ontext/support/ClassPathXmlApplicationContext
at SpringDemo.main(SpringDemo.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.support
.ClassPathXmlApplicationContext
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)
... 1 more
我在我的jdk_version/jre/lib/ext
目录中包含了以下 jar
1) antlr 2) commons-logging-1.1.1 3) spring-beans 4) spring-context 5) spring-core 6) spring-jdbc 7) spring-orm 8) spring-tx
怎么了?我没有从其他相关问题中得到任何帮助。请帮帮我。
提前致谢。