views:

250

answers:

3

I am trying to share Spring object definitions between a web application, unit testing, and possibly a console app. I would like to define the object definitions in one place and import them.

My first pass was to place 'entities.xml' in the same folder as web.config but the relative paths aren't what I expect:

<context>
  <resource uri="config://spring/objects"/>
  <resource uri="file://entities.xml"/>
</context>

and

<objects xmlns="http://www.springframework.net"&gt;
  ...
  <import resource="file://entities.xml" />

produce the same error:

Could not find file 'c:\windows\system32\inetsrv\entities.xml'

the 'current directory' isn't the web app, it's specific to inetsrv.

I would rather not hard-code the full path to this file because it may vary on the test vs. production servers. Is there a better way to share this config info?

+1  A: 

I assume spring.net also allows the classpath:entities.xml syntax, where you put the xml file on the classpath. (Embed it in the module)

krosenvold
+2  A: 

to refer to the root folder of the current application domain, you may use the '~' char:

<resource uri="~/entities.xml"/>

will do exactly what you are looking for.

-Erich

Erich Eichinger
A: 

What is the difference between using <resource> and <import> to refer to external configuration file?

intangible02