This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes FileNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "FileNotFoundException" Watch "FileNotFoundException" New topic
Author

FileNotFoundException

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
when i try to run the following code ,

I am getting the following error:


org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [D:/eclipse/workspace/SpringExample1/beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [D:/eclipse/workspace/SpringExample1/beans.xml] cannot be opened because it does not exist
java.io.FileNotFoundException: class path resource [D:/eclipse/workspace/SpringExample1/beans.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:127)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:144)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:99)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:102)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:70)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:87)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:264)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:80)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:56)
at com.CheckdbController.handleRequest(CheckdbController.java:63)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)



But the beans.xml is in the path mentioned.please assist me to solve this.

Thanks
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
I am confused why you would 'boot up' an application context from inside an action handle method like this, in this case, the path is a constant string (not dynamic based on request parameters), why would you not have the spring context servlet listener start it up for you when the web application starts up ?


ApplicationContext context = new ClassPathXmlApplicationContext("E:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/springhibernate/src/beans.xml");


But this current error here is because you are usung a ClassPathXmlApplicationContext, which wants the String constructor argument to be an expression to some place on the CLASSPATH, for example "/com/mycompany/myapp/beans.xml", where here, this "E:/Apache....src/beans.xml" thing is a file system path,

so try to use the FileSystemApplicationContext here instead.



Error: Keyboard not attached. Press F1 to continue.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Too add to Travis's post. Because you are using a file path, you can still use ClassPathXmlApplicationContext. Just prepend your file path with "file:"


But I agree for a web app, use the Listener.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thanks for your repsonses.Where should i use the listener? and if i prepend file: in the following line



I am getting the error:


org.springframework.beans.factory.BeanDefinitionStoreException: Line 4 in XML document from URL [file:E:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/springhibernate/src/beans.xml] is invalid; nested exception is
org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPEroot "null".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(UnknownSource)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
inside CurrentdateController
firstName
lastName
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:145)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:99)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:102)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:70)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:87)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:264)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:82)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:67)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:58)
at com.HelloWorldApp.run(HelloWorldApp.java:13)
at com.CheckdbController.handleRequest(CheckdbController.java:50)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)


where should i prepend the file:?
Vivek K Singh
Ranch Hand

Joined: Dec 22, 2009
Posts: 85

looks like a spring version mismatch error, Make sure you have spring 2.x jars on your classpath. 1.x uses DOCTYPE... Spring 2.x uses schema...


SCJP 6
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
The project's lib folder consists of the following files:

ant-antlr-1.6.3
antlr-2.7.5H3
asm
asm-attrs
cglib-2.1
commons-collections-2.1.1
commons-dbcp
commons-lang-2.0
commons-logging
commons-logging-1.0.4
commons-pool
dom4j-1.6
ehcache-1.1
hibernate3
hsqldb
j2ee
jstl
spring
springhibernate
standard
xerces-2.6.2



How do i find the jar file's version?

Thanks
Vivek K Singh
Ranch Hand

Joined: Dec 22, 2009
Posts: 85

simpler thing to do will be download spring 2.x jars and replace the ones in lib folder.
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
ok.After that i need to modify anything(version) in xml file also?
Vivek K Singh
Ranch Hand

Joined: Dec 22, 2009
Posts: 85

if you have schemaLocation pointing to 2.x then no change...
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
my beans.xml is as follows:

<?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="helloWorld" class="com.HelloWorldController">
<property name="message" value="1"></property> </bean></beans>


Here in schema location, no version is specified.Where should i find that?
Vivek K Singh
Ranch Hand

Joined: Dec 22, 2009
Posts: 85

change the location to http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thank you so much.It is working fine now.
 
Consider Paul's rocket mass heater.
 
subject: FileNotFoundException
 
Similar Threads
Problem in code
[beans.xml] cannot be opened because it does not exist
Error on threads
Quartz in spring
issue in getting more than one data