HelloWorld Spring application throws Exception in thread "main": java.lang.NoClassDefFound -
i trying develop spring "helloworld" project while runing application gives me error:
info: loading xml bean definitions class path resource [beans.xml] exception in thread "main" java.lang.noclassdeffounderror: org.springframework.expression.expressionparser
below code:
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; } }
and
package com.tutorialspoint; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; public class mainapp { public static void main(string[] args) { applicationcontext context = new classpathxmlapplicationcontext("beans.xml"); helloworld obj = (helloworld) context.getbean("helloworld "); obj.getmessage(); // todo auto-generated method stub } }
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>
apart adding dependent jars seems class
defined within bean
definition invalid
com.tutorialspoint/helloworld ^
make it,
<bean id="helloworld" class="com.tutorialspoint.helloworld"> <property name="message" value="hello world!"/> </bean>
also context.getbean("helloworld ")
should changed context.getbean("helloworld")
Comments
Post a Comment