I'm using xml-based Spring bean configuration. For certain beans, I want to dynamically load the classes based on the different configs. (I could create a parent class for those classes)
Currently I have a workaround solution:
- use of system property tag to dynamically load the class
:
<bean id="dynamicBean" class="com.xyz.${MODEL}MyBeanClass"/>
where MyBean classes are created under different package names, and ${MODEL} will be set to the corresponding package name e.g. "mypackage." at runtime.
The above solution works fine, but I don't see this as a common practice to dynamically initialize a bean in xml-base spring config.
Any cons for this method? and more importantly, what are the alternative ways of achieving the same.