Loading... Cancel

create new url protocol to load spring configuration resource from the relative path R

April 18th, 2008

i had a problem with spring framework, as you know while we are defining dependency over the xml documents, it becomes less changeable unless you know about my recent post about ext-util namespace handler and if you know any other alternatives.

before digging inside the problem better i clarify my context -

i have been working with one of my projects, where i have a several configurations which suppose to be different in different deployment environment, for example - to make my service avail, user has to define his database, his content index directory, server port, ip address and few more.

all these configurations were kept within the spring bean declaration scope. though few of them were moved to the properties file through ext-util namespace handler.

previously to make those configuration changeable i kept those files under WEB-INF/classes so it overrides the default bundled resource.

but still it wasn’t user friendly, since my user has to change one xml document to add more index services also he has to edit different configurations from java properties file.

again when i started bundling jetty with my whole application i found it is tricker to keep those xml outside of application, since i don’t wanna make my user confused with lot of xml files. and i have to keep few xml out of  my classpath context, so spring has to load my configuration from my “config/index-configuration/” directory.

though by default spring can do it over “file:///absolute/path/to/file.xml” since spring is using java URL class to locate this resource.  but in my case i can’t put any aboslute path.
so i found a simple way out there to support relative path reference.

previously i had the following xml document -