Hi,
I'm trying to code my first Spring application using Netbeans
IDE. My application directory structure in the netbeans ide view is as follows.
MySpringApp1--Source Packages--<default package>--newSpringXMLConfig.xml
MySpringApp1--Source Packages--myspringapp1--HelloWorld.java
MySpringApp1--Source Packages--myspringapp1--MySpringApp1.java
When I create a BeanFactory instance in MySpringApp1.java by coding as follows.
I get the following exception.
run:
Feb 11, 2013 10:07:39 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [C:\Users\SomeUser\Documents\NetBeansProjects\MySpringApp1\newSpringXMLConfig.xml]
Exception in
thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [C:\Users\SomeUser\Documents\NetBeansProjects\MySpringApp1\newSpringXMLConfig.xml]; nested exception is java.io.FileNotFoundException: newSpringXMLConfig.xml (The system cannot find the file specified)
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.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
at myspringapp1.MySpringApp1.main(MySpringApp1.java:25)
Caused by: java.io.FileNotFoundException: newSpringXMLConfig.xml (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:110)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 4 more
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
But when I create an ApplicationContext instance by coding as follows,
my code runs fine.
Could somebody please help me resolve the FileNotFoundException I'm getting in the BeanFactory instance case and also help me understand why I'm getting it. Since my xml configuration file is in the default package, why it shouldn't be found?
I have not set CLASSPATH explicitly by either setting it up through command line commands or through environment variables though I ain't sure this is a classpath problem ( or is it? ) cause it works when I create an ApplicationContext instance. Please help.
Thanks so much.