java - Error when calling ClassPathResource.getInputStream() -
i want study spring,i start hello world
i learned make hello world address "http://javacpplus.blogspot.com/2012/04/spring-framework-with-netbeans-70.html[url=http://http://javacpplus.blogspot.com/2012/04/spring-framework-with-netbeans-70.html]webpage[/url]"
and code, make 2 class. 1 helloworld.java , 2 mainapp.java , make 1 xml beans.xml
check out class helloworld.java
package com.hello; /** * * @author bobfuad */ public class helloworld { private string message; public void setmessage(string message){ this.message = message; } public void getmessage(){ system.out.println("your message : " + message); } }
class mainapp.java
package com.hello; mport org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; /** * * @author bobfuad */ public class mainapp { private static resource classpathapplicationcontext; public static void main(string[] args) { applicationcontext context; context = new classpathxmlapplicationcontext("beans.xml"); helloworld obj = (helloworld) context.getbean("helloworld"); obj.getmessage(); } }
beans.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.2.xsd "> <bean id="helloworld" class="com.hello.helloworld"> <property name="message" value="hello world!"/> </bean> </beans>
that it's code, when run program, there have problem
and problem
jun 27, 2014 8:48:44 org.springframework.context.support.abstractapplicationcontext preparerefresh info: refreshing org.springframework.context.support.classpathxmlapplicationcontext@e3849c: startup date [fri jun 27 08:48:44 pdt 2014]; root of context hierarchy jun 27, 2014 8:48:44 org.springframework.beans.factory.xml.xmlbeandefinitionreader loadbeandefinitions info: loading xml bean definitions class path resource [beans.xml] exception in thread "main" org.springframework.beans.factory.beandefinitionstoreexception: ioexception parsing xml document class path resource [beans.xml]; nested exception java.io.filenotfoundexception: class path resource [beans.xml] cannot opened because not exist @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:341) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:302) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:174) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:209) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:180) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:243) @ org.springframework.context.support.abstractxmlapplicationcontext.loadbeandefinitions(abstractxmlapplicationcontext.java:127) @ org.springframework.context.support.abstractxmlapplicationcontext.loadbeandefinitions(abstractxmlapplicationcontext.java:93) @ org.springframework.context.support.abstractrefreshableapplicationcontext.refreshbeanfactory(abstractrefreshableapplicationcontext.java:130) @ org.springframework.context.support.abstractapplicationcontext.obtainfreshbeanfactory(abstractapplicationcontext.java:537) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:451) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:139) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:83) @ com.hello.mainapp.main(mainapp.java:18) caused by: java.io.filenotfoundexception: class path resource [beans.xml] cannot opened because not exist @ org.springframework.core.io.classpathresource.getinputstream(classpathresource.java:157) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:328) ... 13 more java result: 1 build successful (total time: 0 seconds)
please me, thanks
like error message says, beans.xml not found in classpath (in given path, i.e. root). if have placed file next java classes in com/hello
, use path com/hello/beans.xml
in main method.
Comments
Post a Comment