Announcement Announcement Module
Collapse
No announcement yet.
Invalid relative resource location using import statement Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Invalid relative resource location using import statement

    To all,

    When using the <import resource="displays.xml" /> statement in my beans.xml file (they are both in the same directory), I get the following error:

    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionSt oreException: Invalid relative resource location [displays.xml] to import bean definitions from; nested exception is java.io.FileNotFoundException: Cannot create a relative resource for resource loaded through InputStream
    java.io.FileNotFoundException: Cannot create a relative resource for resource loaded through InputStream
    at org.springframework.core.io.AbstractResource.creat eRelative(AbstractResource.java:91)

    Relative? Ok, I tried <import resource="../../../...etc.../displays.xml" /> withough any luck

    Absolute path gives the same error.... :-(

    Any help appreciated
    Barry

  • #2
    Here is some more info.

    my beans.xml actually starts like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>
    <description>
    IDS is an Information Display System
    </description>
    <import resource="displays.xml" />

    Now... If I move the import statement ABOVE the description, I get the following error:

    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionSt oreException: Line 299 in XML document from resource loaded through InputStream is invalid; nested exception is org.xml.sax.SAXParseException: The content of element type "beans" must match "(description?,import*,bean*)".
    org.xml.sax.SAXParseException: The content of element type "beans" must match "(description?,import*,bean*)".

    It doesn't matter in this case wether the displays.xml has a proper xml heading or whether it simply starts with a bean definition, the error remains the same

    Barry

    Comment


    • #3
      Cannot create a relative resource for resource loaded through InputStream
      it sees like you are using
      Code:
      BeanFactory factory = new XmlBeanFactory&#40;inputStream&#41;;
      Using this approach, Spring can not resolve relative resource. Try something like:
      Code:
        Resource resource = new ClassPathResource&#40;"config/applicationContext.xml"&#41;;
        BeanFactory factory = new XmlBeanFactory&#40;resource&#41;;
      or
      Code:
        ApplicationContext context = new ClassPathXmlApplicationContext&#40;"config/applicationContext.xml"&#41;;
      Now... If I move the import statement ABOVE the description, I get the following error:
      import must always be used after description. Spring DTD forces this order.
      HTH

      Comment


      • #4
        Thanks, that did the trick!

        Comment


        • #5
          HI,
          I am trying to refer an on application context file in another

          1st Xml is present at the path /vl-common/src/vlcommonContext.xml (This is the one i am trying to refer)

          2nd Xml is present at the path /vl-download/src/applicationContext.xml

          so my /vl-download/src/applicationContext.xml looks as below.

          Code:
          <beans>
          <import resource="../../vl-common/src/vlcommonContext.xml" />
          but i am not able to do so... and getting the following error on server start up.
          Code:
          [INFO] Loading XML bean definitions from class path resource [applicationContext.xml]
          [INFO] Loading XML bean definitions from class path resource [../../vl-common/src/vlcommonContext.xml]
          [ERROR] Context initialization failed
          org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [../../vl-common/src/vlcommonContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [../../vl-common/src/vlcommonContext.xml] cannot be opened because it does not exist
          java.io.FileNotFoundException: class path resource [../../vl-common/src/vlcommonContext.xml] cannot be opened because it does not exist
          	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:137)
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:167)
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148)
          	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.importBeanDefinitionResource(DefaultXmlBeanDefinitionParser.java:374)
          	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java:338)
          	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:197)
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:295)
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:223)
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173)
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148)
          	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:128)
          	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:144)
          	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:126)
          	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
          	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
          	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:262)
          	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139)
          	at org.springframework.web.struts.ContextLoaderPlugIn.createWebApplicationContext(ContextLoaderPlugIn.java:353)
          	at org.springframework.web.struts.ContextLoaderPlugIn.initWebApplicationContext(ContextLoaderPlugIn.java:296)
          	at org.springframework.web.struts.ContextLoaderPlugIn.init(ContextLoaderPlugIn.java:225)
          	at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:867)
          	at org.apache.struts.action.ActionServlet.init(ActionServlet.java:334)
          Please sugget me some solution.

          Comment


          • #6
            use

            <import resource="classpath:../../vl-common/src/vlcommonContext.xml" />

            ie add classpath: before the filename

            Comment


            • #7
              spring hibernate

              hi dear staff and all

              1 - I have used next but none works

              a - applicationContext = new FileSystemXmlApplicationContext(new String[] {"src/applicationContext.xml"}); // file not found

              b - applicationContext = new FileSystemXmlApplicationContext("src/applicationContext.xml");// file not found

              c - applicationContext = new ClassPathXmlApplicationContext("classpath:src/applicationContext.xml");// file not found

              d -

              2 - errro

              Caused by: java.io.FileNotFoundException: class path resource [src/applicationContext.xml] cannot be opened because it does not exist
              at org.springframework.core.io.ClassPathResource.getI nputStream(ClassPathResource.java:143)
              at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:336)
              ... 15 more

              3 - Do I miss a jar file as I used MyEclipse libraries for hibernate 3.2, spring 2.5 also same error with spring 2.0

              4 - by the way Iuse MyEclipse 8.0 and jboss 4.2.

              many thanks

              Amir

              Comment

              Working...
              X