Montag, 10. September 2007

Spring: Conditional Beans

Recently I faced the problem of creating spring beans depending on values in properties files. Googling round did not show any good solution. I almost wanted to skip the problem then I found an easy solution by just trying something out. Spring offers an mechanism to replace placeholders like "${my.value}" in spring xml files with values from property files (org.springframework.beans.factory.config.PropertyPlaceholderConfigurer)
. Normally you use this for setting values in bean properties for setting attribute values but you can also use it for dynamic references. See example below.