Reputation: 42957
I am trying to do the following Spring "Hello World" example that use the FileSystemXmlApplicationContext as implementation of ApplicationContext interface.
This implementation have to take the full path of the XML bean configuration as constructor parameter, something like the previous example:
ApplicationContext context = new FileSystemXmlApplicationContext("C:/Users/ZARA/workspace/HelloSpring/src/Beans.xml");
I use Linux and my Beans configuration file is under the following path: /home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml, so in my code I have:
ApplicationContext context = new FileSystemXmlApplicationContext("/home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml");
The problem is that when I try to run my application, in the STS\Eclipse console I have the following error message (seems that don't find the file):
INFO: Loading XML bean definitions from file [/home/andrea/Documents/ws/myapplicationcontextexample/home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [/home/andrea/Documents/ws/myapplicationcontextexample/home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml]; nested exception is java.io.FileNotFoundException: home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml (File o directory non esistente)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at org.andrea.myexample.myapplicationcontextexample.MainApp.main(MainApp.java:14)
Caused by: java.io.FileNotFoundException: home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml (File o directory non esistente)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:113)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 13 more
Why? How can I solve?
Tnx
Andrea
Upvotes: 1
Views: 10715
Reputation: 91
NOTE: Plain paths will always be interpreted as relative to the current VM working directory, even if they start with a slash. (This is consistent with the semantics in a Servlet container.) Use an explicit "file:" prefix to enforce an absolute file path.
Upvotes: 8