Results 1 to 4 of 4

Thread: entity ref includes in spring beans xml

  1. #1
    Join Date
    Oct 2004
    Posts
    1

    Default entity ref includes in spring beans xml

    We're trying to sort out how to deploy to various environments that need slightly different configurations in spring-beans.xml (i.e. local jdbc verses jndi datasources etc.). Initially I thought that entity ref style includes would be good, but they don't seem to work.

    I have the following in my spring beans xml:

    <!DOCTYPE beans PUBLIC "..." "..." [
    <!ENTITY datasource SYSTEM "datasource.xml">
    ]>

    ...
    &datasource;
    ...

    For junit tests we use:

    context = new ClassPathApplicationContext("spring-beans.xml")

    And the entity ref fails with

    org.xml.sax.SAXParseException: Relative URI "datasource.xml"; can not be resolved without a base URI.

    Which is because in the context construction there is no scheme (i.e. "file:///..."). The location of things is different on various machines and absolute references are not going to work. Is there some other way to set the base URI?

    Any ideas on a good way to deal with this would be appreciated.

    Presumably it's a fairly common problem (multiple configurations for different environments like development, cruisecontrol, testing, qa, production, etc.)

    Thanks,
    Derek

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

    Default

    how about configuring beans in multiple files and using
    Code:
    String locations&#91;&#93; = &#123;"file1.xml","file2.xml"&#125;;
    context = new ClassPathApplicationContext&#40;locations&#41;;
    HTH
    Omar Irbouh

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

  3. #3
    Join Date
    Oct 2004
    Location
    Not Redmond
    Posts
    26

    Default
    Hi

    Have you tried using the <import/> element that was added in the latest release of Spring?

    Code:
    <beans>
        <import resource="datasource.xml"/>
        <bean>...</bean>
        <bean>...</bean>
    </beans>
    This should solve your problem (assuming that you can upgrade to the latest version of Spring :wink.

    Later
    .NET Guy


  4. #4
    Join Date
    Nov 2004
    Location
    Los Angeles, CA
    Posts
    5

    Default

    Along those lines, I am using <import/> but need to import an XML files from a different JAR in the classpath. Is this possible?

    I have some abstract beans declared in XML files in the frramework JAR and individual projects need to include and subclass.

    I tried various forms of

    <import resource="cdpUtilities.jar!/HibernateDataSource.xml"/>

    with no luck.

    For now I have the included file copied into each project. Even worse, I haven't found a cleaner way to import it from subpackages other than

    <import resource="../../../../HibernateDataSource.xml"/>

    Just "/Hibernate..." didn't work.

    Now that I think about it, the only way that's working is when the files are in the build/test/classes directory -- not in a JAR. Can you import from a JAR?

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. Replies: 0
    Last Post: Aug 25th, 2005, 05:11 AM
  3. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  4. Other Hibernate DAO LazyInitializationExceptions
    By bernardsirius in forum Data
    Replies: 5
    Last Post: Feb 18th, 2005, 04:09 PM
  5. Replies: 9
    Last Post: Feb 8th, 2005, 09:25 PM

Posting Permissions

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