Announcement Announcement Module
Collapse
No announcement yet.
class path resource applicationContext.xml not found Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • class path resource applicationContext.xml not found

    Hi, im a new spring developer.

    I have a spring based java-application this will be initiated from a linux script like this:

    Code:
    java -cp "applicationContext.xml:lib/*" com.project.imports.TaskStarterApp
    I have placed the applicationContext.xml file in every folder on the linux-server, to be sure that is found.

    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:

    Code:
    /* this gives an error */
    new ClassPathXmlApplicationContext("applicationContext.xml").getBean(myBusinessLayer.class);
    
    /*ive also tried with this: */
    new ClassPathXmlApplicationContext("/applicationContext.xml").getBean(myBusinessLayer.class);
    /* given exception */
    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.
    Last edited by bashirshaz; Oct 26th, 2012, 06:27 AM.

  • #2
    solved....it was me just setting the classpath wrongly

    Comment


    • #3
      This is quite common with people not setting their classpath correctly and thinking there's a problem with the code or the framework. I recommend analyzing the stack-trace and make sure that it is a genuine abnormal condition before posting the problem.

      Comment

      Working...
      X