1
votes

I have a simple Spring.NET demo, and I'm trying to have a shared object file that would reside on a shared drive. This works if I pass in the UNC path as a resource file to the constructor, but if use an <import resource construct it interprets it as relative, which is not supported. Is there a way I can use the import statement with a UNC path?

Works:

<context>
  <resource uri="config://spring/objects"/>
  <resource uri="\\server\share\folder\SpringConfig.xml"/>
</context>

Doesn't work:

<import resource="\\server\share\folder\SpringConfig.xml"></import>

Error message:

System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': ConfigSectionResource does not support relative resources. Please use fully qualified resource name. ---> Spring.Objects.Factory.ObjectDefinitionStoreException: Error registering object defined in 'config [C:\Users\user\documents\visual studio 2010\Projects\SpringExample\SpringExample\bin\Debug\SpringExample.vshost.exe.Config#spring/objects] at line 1' : Failed parsing element ---> System.NotSupportedException: ConfigSectionResource does not support relative resources. Please use fully qualified resource name.

3

3 Answers

3
votes

Use the fully qualified resource string and use forward slashes throughout:

<objects xmlns="http://www.springframework.net">
  <import resource="file:////server/share/folder/SpringConfig.xml" />
</objects>

Note that file: protocol identifier is followed by four slashes, two belong to the protocol and two to the server location. Worked on my machine :). This also works:

<objects xmlns="http://www.springframework.net">
  <import resource="file://\\server\share\folder\SpringConfig.xml" />
</objects>
2
votes

Hmmm.. This should work. What I don't understand is why ConfigSectionResource throw the exception. FileSystemResource should be used by default in a non Web application.

What version of Spring.NET are you using ? Are you using CodeCondig extension ?

Anyway, this should work:

<resource uri="file://\\server\share\folder\SpringConfig.xml"/>
0
votes

I'm honestly not certain whether UNC paths are supported or not, but if you want a fully-qualified file path, you need to use <resource uri="file://c:/folder1/folder2/MyConfig.xml" /> IIRC.