Apr 27th, 2007, 03:15 PM
Token replacement or similur
Is it possible to have some kind of token replace in the spring configuration files. As an example we start with a different configuration file for development and production with some basic differences in this files, such as the DataSource. We then include files that are the same for both environments using the <import> tag.
However, we now have some need for something to change in these detail files for the different environments. We could include deferent files for each environment but that would mean the included files would be identical except for one property.
Some kind of token definition in file 'A' that can then be used in the included file 'B' would be ideal.
Apr 27th, 2007, 03:20 PM
Apr 27th, 2007, 03:30 PM
I saw that capability but was hoping there was something that could be done just in the spring configration files, I.E., not have to have a seperate property file.
Apr 27th, 2007, 03:35 PM
Actually in reading the Java doc it looks like default properties can be set. That might work. Let me try it.
Apr 27th, 2007, 05:44 PM
If you could post back either way that would be good. I'm just trying to understand the details of what you are trying to do.
May 2nd, 2007, 12:21 PM
I did get this working using the following:
xml in our main spring conf file: There would be one of these for production, development, staging, etc.
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
We have a separate hibernate configuration file that creates the session factories. You can use the token generated above in there as so: That way we don't have to have seperate ones for production, etc.
<prop key="hibernate.dialect">org.hibernate.dialect.DB23 90Dialect</prop>
We don't use ApplicationContext so we must manually instantiate the bean:
PropertyPlaceholderConfigurer pc = (PropertyPlaceholderConfigurer) beanFactory.getBean("propertyConfigurer");
pc.postProcessBeanFactory((ConfigurableListableBea nFactory) beanFactory);