Loading...
within spring container i was getting problem with managing multi level configuration.
for example while i am developing i got a specific filesystem path, database configuration and so on.
this configuration are mostly get changed while i an deploying them on the test or production environment.
this type of scenario is common on most of the projects. managing different scoped configuration is one of the bothering stuff. so i was always thinking some simpler way with in spring container.
so i wrote “ext-util” namespace handler, which is locating property from multi scoped resource.
lets give you a more details use case -
in my test environment i have a property “index.directory=/Users/…/index”
in my test server i use “index.directory=/var/index”
in my production server i use “index.directory=/nfs/index”
here i have a bean which need this property.
< bean id="fsDirectory" class="org.springmodules.lucene.index.support.FSDirectoryFactoryBean" >
< property name="location" value="file:////Users/nhmtanveerhossainkhanhasan/java-tmp/index" / >
< /bean>
you can see the hardcoded configuration. which is not easy to manage.
thats why here my “ext-util” goes with the simplest solution -
< ext-util:resource id="directoryResource" from-property="index.directory" scope="test" / >
< bean id="fsDirectory" class="org.springmodules.lucene.index.support.FSDirectoryFactoryBean" >
< property name="location" ref="directoryResource" / >
< /bean>
now my property resource is locating from “test” scope.
you might think, this “scope=’test’” is again hardcoded stuff, so i also support the following value -
scope=”sys:env”, now you have to define “-Denv=test” while you running your application, and spring bean will find the right property.
so what ever you put over your spring are no longer hardcoded as long as you locate them through “ext-util” which is stands for “extended utility”.
how to use -
include the source file with in your project
keep “META-INF” while you building your jar or keep them inside your classpath.
change your spring configuration -
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:lang=”http://www.springframework.org/schema/lang”
xmlns:aop=”http://www.springframework.org/schema/aop”
xmlns:ext-util=”http://dev.somewherein.net/schema/ext-util”
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://dev.somewherein.net/schema/ext-util http://dev.somewherein.net/resources/schemas/ext-util-0.1.xsd“/>
basic properties of ext-util -
1. from-property - which property you are looking for.
2. or-default - define default value if no property is found from default scope (system properties) this value is returned.
3. scope - define scope name, by default whatever you set except “sys:” prefixed string, will search for “classpath:”. also you can use “sys:abc” where abc is located from system properties.
4. path-prefix - you can define scope properties path prefix, this prefix can be “file:///, classpath:”. this value also can be prefixed by “sys:abc” where abc is located from system properties.
[download source code]
[download missing xsd file]
best wishes,







| www.flickr.com |
Leave a reply