HelloWorld Spring应用程序在线程中引发异常;主要内容:找到java.lang.noClassDef
我试图在运行该应用程序时开发一个Spring“HelloWorld”项目,但它给了我以下错误:HelloWorld Spring应用程序在线程中引发异常;主要内容:找到java.lang.noClassDef,java,spring,Java,Spring,我试图在运行该应用程序时开发一个Spring“HelloWorld”项目,但它给了我以下错误: com.tutorialspoint/HelloWorld ^ 信息:从线程“main”java.lang.NoClassDefFoundError中的类路径资源[Beans.XML]异常加载XML bean定义:org.springframework.expression.ExpressionParser com.tutorialspoint/HelloWorl
com.tutorialspoint/HelloWorld
^
信息:从线程“main”java.lang.NoClassDefFoundError中的类路径资源[Beans.XML]异常加载XML bean定义:org.springframework.expression.ExpressionParser
com.tutorialspoint/HelloWorld
^
下面是我的代码:
package com.tutorialspoint;
public class HelloWorld {
private String message;
public void getMessage() {
System.out.println("your message : "+message);
}
public void setMessage(String message) {
this.message = message;
}
}
com.tutorialspoint/HelloWorld
^
及
com.tutorialspoint/HelloWorld
^
ApplicationContext.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-3.0.xsd">
<bean id="helloWorld" class="com.tutorialspoint/HelloWorld">
<property name="message" value="Hello World!"/>
</bean>
</beans>
com.tutorialspoint/HelloWorld
^
包括
com.tutorialspoint/HelloWorld
^
spring-expression-3.1.1.Release.jar
com.tutorialspoint/HelloWorld
^
在lib
文件夹下
com.tutorialspoint/HelloWorld
^
我提到了3.1.1作为示例,您可以使用最新版本(如果有的话)。除了添加所有依赖的jar之外,
bean中定义的类
似乎是无效的
com.tutorialspoint/HelloWorld
^
成功了
com.tutorialspoint/HelloWorld
^
<bean id="helloWorld" class="com.tutorialspoint.HelloWorld">
<property name="message" value="Hello World!"/>
</bean>
另外,应该将context.getBean(“helloWorld”)
更改为context.getBean(“helloWorld”)
将spring依赖项添加到类路径中如果您没有使用Maven,如M Sach所说,将“spring expression-X.Release.jar”添加到“lib”中文件夹,也不要忘记将其添加到Eclipse中的构建路径中此与spring-expression.jar相关的异常添加此项。有关spring依赖项的相关问题:。请务必查看您的库列表。
com.tutorialspoint/HelloWorld
^