PDA

View Full Version : Using <import> tag with WebApplicationContext


darrell.pittman
10-10-2005, 12:28 PM
I'm having a problem with using an <import resource="business-facade-obj.xml"/> tag in an xml file that is referenced in the Web.Config file as follows:

<spring>
<context
type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="~/XmlData/SpringObjects/main-objects.xml"/>
</context>
</spring>

The main-objects-xml file contains the <import> tag mentioned above. It seems that when a WebApplicationContext is created it calls AddProtocolMapping("web", typeof(WebResource));
but when it comes to the <import> tag, the AbstractResource object creates a new ConfigurableResourceLoader (which doesn't contain this mapping) and an error is thrown because of the unknown protocol.

Is there something special I have to do to use an <import> tag in a web application xml file?

Rick Evans
10-10-2005, 02:24 PM
Hi

Nope, that's a bug.

I really don't know if I should say this :), but I have always felt that the <import/> element is a hack. You can always supply a list of the resources that make up a context anyway, so I don't really see what the <import/> element buys you... the logical separation of one's object definitions can be accomplished by the aformentioned means, so well, the <import/> element seems kinda redundant . It was present in Spring, so it was ported for parity, but well... yeah :?

I'll get that bug addressed in the 1.1 timeframe. We're looking into a number (http://opensource2.atlassian.com/projects/spring/browse/SPRNET-199) of ways (http://opensource2.atlassian.com/projects/spring/browse/SPRNET-116) to make custom resource protocol registration easier anyways, so this will be part of that effort.

Cest la vie and all that, ciao
Rick

Mmm, that response seems a tad flippant (its not meant to be). The issue you have raised is a bona fide bug, thanks for spotting it... it will be addressed shortly, I'll see to that. In the interim, you can always supply multiple resource names to the configuration of your contexts in your web.config file (which is the usage style that I would personally recommend).

darrell.pittman
10-10-2005, 05:48 PM
Rick,

Thanks for the reply. I'm new to spring and just going through it and and trying things out. I saw the <import> tag in the documentation and thought I had to import the files.

If there is no difference between importing and using multiple resource declarations then no problem. I wasn't sure if there was some kind a dependency between objects that would require using <import>.