Announcement Announcement Module
Collapse
No announcement yet.
multiple xml configuration files Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • egauthier
    started a topic multiple xml configuration files

    multiple xml configuration files

    Hello,
    Is it possible to use multiple xml configuration files for one context?
    I have a very large config file that I would like to cut in separate parts but i need to make cross references between beans defined in the different parts.

    thanks

  • robh
    replied
    Just to clarify the details in this post. When declaring a <bean> with an id that id value is mapped to an actual XML id that can be validated by the parser. When using <ref local="..."/> the value of the local attribute is validated, by the XML parser, against all the XML ids in the SAME file. To refer to a bean in another file but in the same logical context you need to use <ref bean="..."/>. Here the bean attribute is NOT validated by the XML parser and is validated instead by Spring. This allows you to define beans ids that are outside the current file.

    So to summarise:

    <ref local="..."/> will validate the local attribute against bean ids in the same file and <ref bean="..."/> will not.

    Rob

    Leave a comment:


  • rafeco
    replied
    It sounds like something is set up wrong. If you're using "ref bean" then the XML content handler shouldn't even try to resolve those references -- it should be handled at the next level up, after all of the files have been parsed.

    Leave a comment:


  • cmgharris
    replied
    I'm afraid I don't know. I imagine it's whatever comes with jboss. If you can tell me how to find out, I'll be happy to do that.

    Leave a comment:


  • davidr
    replied
    what xml parser are you using?

    Leave a comment:


  • cmgharris
    replied
    It definitely works with id's. None of my beans have names and I can reference them from one file to another.

    Leave a comment:


  • davidr
    replied
    I have given the beans ids and not names and the error i am getting is from the XML parser. Perhaps it is the opposite, that i should use names instead of id's? I guess we can try that

    Leave a comment:


  • rafeco
    replied
    It definitely works. You can reference beans from one file to another. You need to use "ref bean" instead of "ref local" and I think you also need to give your beans ids instead of names.

    Leave a comment:


  • davidr
    replied
    I found a post that indicatees that this is doable but when we tried it and we used <ref bean= instead of ref local, but we still got an error from Spring telling us:
    "An element with the identifier "primaryDataSource" must appear in the document."

    Leave a comment:


  • davidr
    replied
    And can we reference beans from one file to another?

    Leave a comment:


  • Ben Alex
    replied
    See Spring Reference Guide section 3.15, "Creating an ApplicationContext from a web application", for details on how to do this in a webapp.

    In a non-webapp situation (eg unit test) you just do this:

    Code:
    private String&#91;&#93; configLocations = &#123;"/appctx-datastore.xml", "/appctx-security-relaxed.xml"&#125;;
    new ClassPathXmlApplicationContext&#40;configLocations&#41;;

    Leave a comment:

Working...
X