-
Apr 27th, 2007, 03:15 PM
#1
Token replacement or similur
Hi,
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.
Any ideas?
Scott
Scott N
-
Apr 27th, 2007, 03:20 PM
#2
-
Apr 27th, 2007, 03:30 PM
#3
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.
Scott N
-
Apr 27th, 2007, 03:35 PM
#4
Actually in reading the Java doc it looks like default properties can be set. That might work. Let me try it.
Scott N
-
Apr 27th, 2007, 05:44 PM
#5
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
#6
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">
<property name="properties">
<props>
<prop key="default_schema">ADVJPMT</prop>
</props>
</property>
</bean>
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.
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DB23 90Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.lazy">true</prop>
<prop key="hibernate.default_schema">${default_schema}</prop>
</props>
</property>
We don't use ApplicationContext so we must manually instantiate the bean:
PropertyPlaceholderConfigurer pc = (PropertyPlaceholderConfigurer) beanFactory.getBean("propertyConfigurer");
pc.postProcessBeanFactory((ConfigurableListableBea nFactory) beanFactory);
Scott
Scott N
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules