The module create a customized PropertyPlaceholderConfigurer which load properties from Zookeeper. And also with properties changing in Zookeeper server, the module will trigger SpringFramework context reload.
There're 2 ways to load the module when you use SpringFramework as application container
-
Bean Style
a. add jar to the classpath.
b. in your spring application context definition XML add following bean definition
c. put zk.properties into classpath:/config/, change value according to annotations
-
Customized Schema Style
a. add jar to the classpath.
b. add tag schema declaration and tag body in application context definition XML
<beans ...
xmlns:zk="http://futureseeds.com/schema/zookeeper"
xsi:schemaLocation="
...
http://futureseeds.com/schema/zookeeper http://futureseeds.com/schema/tags/zkconfigurer.xsd
...">
...
...
c. put zk.properties into classpath:/config/, change value according to comments, or you can define the config in context
XML, by using tag:
instead of by zkResource.initializeBy = "LOCAL_FILE".
Then you can Use ${propName} to take reference just like when you use PropertyPlaceholderConfigurer, if property defined in zookeeper znodes, value will be set.
Notice:
- Both load methods have been tested in Spring Framework 2.5.6 and passed.
- If you've one or more PropertyPlaceholderConfigurer, remember to set 'order' attribute and 'ignoreUnresolvablePlaceholders' to every placeholderConfigurer.
Attribute 'order' decides the precedence of your resource. 0 is most important, default value is 2^31-1, which is the lowest precedence. Lowest precedence means once variable conflict encountered, variable read from your config will always be overwritten!
Attribute 'ignoreUnresolvablePlaceholders' must be set to 'true' or unexpected result will come. (Customized schema tag has set the value so you just need keep notice on bean style definitions)
- One can disable automatic context reload by changing setting in zk.properties from 'reload_context=AUTO' to 'reload_context=HOLD'.
JMX is under consideration to be used to expose interface of trigger manually reload.
- UI for znode control will be also part of it. Under investigation.
- Currently property file with XML format is not supported. Not sure but said Spring 3.X will support XML resource by nature.
- No test of perm memory leak on Spring context reload, if you encounter, check whether your beans, especially those connection-keeping beans, have reclaim the resource or not when bean disposed. If everything fine with your beans, your lucky to fire bugs to Spring Framework.
Have Fun!
james.wu.shanghai@gmail.com
May 2013