| Author |
FileNotFoundException for context file
|
Sonny hodac
Greenhorn
Joined: Jan 31, 2008
Posts: 8
|
|
I tried to load the context file for a test case, using a absolute path: private ApplicationContext context; context = new ClassPathXmlApplicationContext("C:/myfolder/springapp-context.xml"); But it didn't work, got this exception: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [C:/myfolder/springapp-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [C:/myfolder/springapp-context.xml] cannot be opened because it does not exist Caused by: java.io.FileNotFoundException: class path resource [C:/myfolder/springapp-context.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:307) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:173) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66) at com.apria.savvion.persistence.service.ApriaCustomInterfaceService.<init>(ApriaCustomInterfaceService.java:76) at com.apria.savvion.persistence.service.test.ApriaCustomInterfaceServiceTest.setUp(ApriaCustomInterfaceServiceTest.java:18) at junit.framework.TestCase.runBare(TestCase.java:125) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Can someone give some input of what I'm doing wrong here? Thanks,
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
If you're using a full path, use FileSystemXmlApplicationContext instead, because ClassPathXmlApplicationContext will search from your classpath.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Sonny hodac
Greenhorn
Joined: Jan 31, 2008
Posts: 8
|
|
|
thanks. i will try and let you know the result.
|
 |
Sonny hodac
Greenhorn
Joined: Jan 31, 2008
Posts: 8
|
|
I tried the FileSystemXmlApplicationContext, still got the same error. Please help: context = new FileSystemXmlApplicationContext("file:C:/myfolder/spring-context.xml"); org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:C:/myfolder/spring-context.xml]; nested exception is java.io.FileNotFoundException: C:/myfolder/spring-context.xml (The system cannot find the file specified) Caused by: java.io.FileNotFoundException: C:/myfolder/spring-context.xml(The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:129) at java.io.FileInputStream.<init>(FileInputStream.java:89) at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:103) at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:191) at org.springframework.core.io.UrlResource.getInputStream(UrlResource.java:103) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:307) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:173) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324) at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:124) at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:68) at com.apria.savvion.persistence.service.ApriaCustomInterfaceService.<init>(ApriaCustomInterfaceService.java:77) at com.apria.savvion.persistence.service.test.ApriaCustomInterfaceServiceTest.setUp(ApriaCustomInterfaceServiceTest.java:18) at junit.framework.TestCase.runBare(TestCase.java:125) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
|
Is there a file called spring-context.xml in myfolde ? At the DOS prompt, try "DIR C:/myfolder/spring-context.xml".
|
 |
Sonny hodac
Greenhorn
Joined: Jan 31, 2008
Posts: 8
|
|
Here is the code that load the context: context = new FileSystemXmlApplicationContext("file:C:\\sbm\\bpm\\Savvion\\BPMStudio\\ApriaSonataDataAdminEJB\\saddAppDev-context.xml"); I do dir at dos prompt for my context file, here the result: C:\>dir c:\sbm\bpm\Savvion\BPMStudio\ApriaSonataDataAdminEJB\sdaaAppDev-context. xml Volume in drive C is CDRIVE Volume Serial Number is F879-9537 Directory of c:\sbm\bpm\Savvion\BPMStudio\ApriaSonataDataAdminEJB 02/01/2008 11:25 AM 1,929 sdaaAppDev-context.xml 1 File(s) 1,929 bytes 0 Dir(s) 28,175,286,272 bytes free I ran the Junit test again still got the exception, please help, here the exception: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:C:/sbm/bpm/Savvion/BPMStudio/ApriaSonataDataAdminEJB/saddAppDev-context.xml]; nested exception is java.io.FileNotFoundException: C:\sbm\bpm\Savvion\BPMStudio\ApriaSonataDataAdminEJB\saddAppDev-context.xml (The system cannot find the file specified) Caused by: java.io.FileNotFoundException: C:\sbm\bpm\Savvion\BPMStudio\ApriaSonataDataAdminEJB\saddAppDev-context.xml (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:129) at java.io.FileInputStream.<init>(FileInputStream.java:89) at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:103) at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:191) at org.springframework.core.io.UrlResource.getInputStream(UrlResource.java:103) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:307) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:173) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324) at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:124) at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:68) at com.apria.savvion.persistence.service.ApriaCustomInterfaceService.<init>(ApriaCustomInterfaceService.java:88) at com.apria.savvion.persistence.service.test.ApriaCustomInterfaceServiceTest.testSearchQueue(ApriaCustomInterfaceServiceTest.java:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60) at java.lang.reflect.Method.invoke(Method.java:391) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
Ok, and you don't find anything weird ? Look closely and don't pull your hair out Your context path : file:C:\\sbm\\bpm\\Savvion\\BPMStudio\\ApriaSonataDataAdminEJB\\saddAppDev-context.xml The real path : c:\sbm\bpm\Savvion\BPMStudio\ApriaSonataDataAdminEJB\sdaaAppDev-context.xml
|
 |
Sonny hodac
Greenhorn
Joined: Jan 31, 2008
Posts: 8
|
|
|
Oh...my bad...after watch the same error for a while everything is blurry abit...thanks so much for pointing it out.
|
 |
 |
|
|
subject: FileNotFoundException for context file
|
|
|