Reputation: 31848
I have a Spring.NET program with a configuration file. To smooth the transition from test to prod I'd like to have an environment variable that gives the path to a shared config file, and use that to import a resource, however it appears the <import resource="path"/>
is not being resolved. For example if I try to load the file <import resource="\\server\share\${computername}\SpringConfig.xml"/>
I get a file not found exception as below:
System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': file [\server\share\${computername}\SpringConfig.xml] cannot be resolved to local file path - resource does not use 'file:' protocol. ---> Spring.Objects.Factory.ObjectDefinitionStoreException: IOException parsing XML document from file [\server\share\${computername}\SpringConfig.xml] ---> System.IO.FileNotFoundException: file [\server\share\${computername}\SpringConfig.xml] cannot be resolved to local file path - resource does not use 'file:' protocol.
Is there a way I can have a dynamic import path in Spring.NET, preferably without writing code?
Upvotes: 3
Views: 2934
Reputation: 1183
You can do that anyway with some extra code:
Create your own FileSystemResource that will replace placeholders in the resource name. Start from overriding the existing FileSystemResource (In Spring.Core.IO namespace)
Register your new IResource implementation in the container using your own protocol name (ex: myfile://) See ref docs here for an example :
Use it! resource="myfile://\server\share\${computername}\SpringConfig.xml"
Upvotes: 5
Reputation: 1183
I don't think we can do that with the current version. Latest Java version supports it, so we can expect this feature in a future version (Using variables environnement by default)
Upvotes: 2