Spring Beginner - No such field error -
i new spring. developing 1 sample project using spring. getting following exception when provide value in beans.xml. please provide solution.
beans.xml:
<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.dhr.spring.beans.helloworld"> <property name="message" value="d" /> </bean> </beans>
helloworld.java:
public class helloworld { private string message; public void setmessage(string message){ this.message = message; } public void getmessage(){ system.out.println("your message : " + message); } }
mainapp:
public class mainapp { public static void main(string[] args) { applicationcontext context = new classpathxmlapplicationcontext("beans.xml"); helloworld obj = (helloworld) context.getbean("helloworld"); obj.getmessage(); } }
exception:
caused by: java.lang.nosuchfielderror: null @ org.springframework.expression.typedvalue.<clinit>(typedvalue.java:31) @ org.springframework.expression.spel.support.standardevaluationcontext.setrootobject(standardevaluationcontext.java:85) @ org.springframework.expression.spel.support.standardevaluationcontext.<init>(standardevaluationcontext.java:74) @ org.springframework.context.expression.standardbeanexpressionresolver.evaluate(standardbeanexpressionresolver.java:124) @ org.springframework.beans.factory.support.abstractbeanfactory.evaluatebeandefinitionstring(abstractbeanfactory.java:1299) @ org.springframework.beans.factory.support.beandefinitionvalueresolver.evaluate(beandefinitionvalueresolver.java:210) @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvevalueifnecessary(beandefinitionvalueresolver.java:182) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applypropertyvalues(abstractautowirecapablebeanfactory.java:1360) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1118) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:517) ... 11 more
welcome! ambiguous world of spring! stack traces long , documentation short convoluted.
i have seen error several times and, @ least me, has dependency inconsistencies.
i see posted not using maven. can assure that problem. should using maven. amount of work save monumental.
edit: make post more answer-like: getting error due dependency inconsistencies. manually putting spring jar files dependency tree not recommended. either 1) use maven handle dependency management (recommended) or 2) ensure jar files utilize non-conflicting , coherent dependency trees.
for instance, using org.springframework.expression-3.0.3.release
not part of 3.1.x
group. so, replace jar file org.springframework.expression-3.1.0-release
Comments
Post a Comment