Hi, im a new spring developer.
I have a spring based java-application this will be initiated from a linux script like this:
I have placed the applicationContext.xml file in every folder on the linux-server, to be sure that is found.Code:java -cp "applicationContext.xml:lib/*" com.project.imports.TaskStarterApp
The TaskStarterApp is called successfully. But when i try to load the applicationContext.xml file in my class, i get an error that its not found:
/* given exception */Code:/* this gives an error */ new ClassPathXmlApplicationContext("applicationContext.xml").getBean(myBusinessLayer.class); /*ive also tried with this: */ new ClassPathXmlApplicationContext("/applicationContext.xml").getBean(myBusinessLayer.class);
Code:- Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@18fe7c3: startup date [Fri Oct 26 13:14:55 CEST 2012]; root of context hierarchy - Loading XML bean definitions from class path resource [applicationContext.xml] TaskStarter: Exception occured: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist 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:143) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.project.imports.TaskStarterApp.main(TaskStarterApp.java:59) Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) ... 19 more
cant figure out how the application can find the applicationContext.xml file. how can i set the applicationContext.xml file in classpath. When i try to run the same code in eclipse, the file is found, as its in classpath already.
i appreciate all help.


Reply With Quote