View Full Version : multiple xml configuration files
egauthier
Sep 11th, 2004, 01:17 PM
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
Ben Alex
Sep 11th, 2004, 04:43 PM
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:
private String[] configLocations = {"/appctx-datastore.xml", "/appctx-security-relaxed.xml"};
new ClassPathXmlApplicationContext(configLocations);
davidr
Sep 23rd, 2004, 07:34 AM
And can we reference beans from one file to another?
davidr
Sep 23rd, 2004, 07:47 AM
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."
rafeco
Sep 23rd, 2004, 10:04 AM
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.
davidr
Sep 23rd, 2004, 10:14 AM
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
cmgharris
Sep 23rd, 2004, 10:40 AM
It definitely works with id's. None of my beans have names and I can reference them from one file to another.
davidr
Sep 23rd, 2004, 10:51 AM
what xml parser are you using?
cmgharris
Sep 23rd, 2004, 10:54 AM
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.
rafeco
Sep 23rd, 2004, 11:09 AM
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.
robh
Sep 23rd, 2004, 12:16 PM
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
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.