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

  • 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

  • #2
    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[] configLocations = {"/appctx-datastore.xml", "/appctx-security-relaxed.xml"};
    new ClassPathXmlApplicationContext(configLocations);

    Comment


    • #3
      And can we reference beans from one file to another?

      Comment


      • #4
        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."

        Comment


        • #5
          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.

          Comment


          • #6
            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

            Comment


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

              Comment


              • #8
                what xml parser are you using?

                Comment


                • #9
                  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.

                  Comment


                  • #10
                    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.

                    Comment


                    • #11
                      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

                      Comment

                      Working...
                      X