Results 1 to 7 of 7

Thread: Invalid relative resource location using import statement

  1. #1
    Join Date
    Jan 2005
    Posts
    14

    Default 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. #2
    Join Date
    Jan 2005
    Posts
    14

    Default

    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

  3. #3
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  4. #4
    Join Date
    Jan 2005
    Posts
    14

    Default

    Thanks, that did the trick!

  5. #5
    Join Date
    Sep 2007
    Posts
    15

    Default

    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.

  6. #6
    Join Date
    Jan 2009
    Posts
    3

    Default

    use

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

    ie add classpath: before the filename

  7. #7
    Join Date
    Oct 2009
    Posts
    4

    Default 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

Similar Threads

  1. Acegi in portlets
    By dreed in forum Security
    Replies: 37
    Last Post: Apr 27th, 2008, 06:34 AM
  2. Date Format Control within Forms
    By milestone in forum Swing
    Replies: 9
    Last Post: Oct 11th, 2005, 01:04 PM
  3. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  4. Replies: 3
    Last Post: Sep 22nd, 2005, 10:14 AM
  5. Transaction Management
    By caverns in forum Data
    Replies: 3
    Last Post: Mar 8th, 2005, 06:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •