How many times have you been on a project, and people are talking about where to share configuration data?
Do I use some constants? What about a config file (XML, properties, etc)?
Sometimes it isn’t easy to know what to do, and you sometimes end up with duplicate information.
For example, what if you want to share database information between your code, your ant build, and anything else?
With Spring, you can use their really nice PropertyPlaceholderConfigurer, and easily share a properties file. You can simply share one properties file for all of your build info as well as Spring sharing, or you can of course seperate things out, and have multiple <property file=”filename”/>’s in your build script.
So, the steps for sharing the data:
1. Setup your properties
# DB Info
jdbc.driver=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:db/myapp
jdbc.user=sa
jdbc.password=
jdbc.maxConnections=25
2. Setup and use these properties in Spring
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:project.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>${jdbc.driver}</value></property>
<property name="url"><value>${jdbc.url}</value></property>
<property name="username"><value>${jdbc.user}</value></property>
<property name="password"><value>${jdbc.password}</value></property>
</bean>
3. Use these properties in Ant
<property file="project.properties"/>
...
<target name="browse">
<java classname="org.hsqldb.util.DatabaseManager" fork="yes" failonerror="true">
<classpath refid="classpath"/>
<arg value="-url"/>
<arg value="${jdbc.url}"/>
</java>
</target>
Easy as pie. Just another small example of how it is a pleasure to work with Spring. I remember futsing around for hours with how to do configuration with JNDI and EJB. What do you put in <env-entry>’s? Ergh. Not anymore!

August 3rd, 2005 at 5:18 pm
Also, another issue which I didn’t mention in my post is regarding theoretical groundings of information science(s)/studies. Here as well, there are theories regarding separate research focuses (information retrieval, information seeking, information behaviors, etc…). However, these sound like theoretical frameworks for various sub-disciplines of information studies rather than Information Science (singular). What is that ‘thing’ that ties all the information sciences (plural) together, besides for the fact that they all claim to be dealing with the ‘thing’ called ‘information’ - which is not necessarily defined the same across the various concentrations and research areas within information science/studies.
November 24th, 2005 at 11:36 am
This info really helps.
Many thanks
November 24th, 2005 at 11:37 am
This info really helps.
Many thanks
May 17th, 2006 at 6:09 am
Hi,
How do u fetch a integer value from properties file?
May 17th, 2006 at 6:11 am
Hi,
How do u fetch a integer value from properties file?
Thanks,
Shilpa
July 20th, 2006 at 5:20 am
Nice info indeed. One small problem, though: how do you use one PropertyPlaceholderConfigurer over multiple bean definition files in a web application (let’s say you have an xml for acegi related beans, one for domain beans and one for each servlet you proxy through spring)?
October 23rd, 2006 at 8:56 am
Great Info. Thanks.
October 24th, 2006 at 7:54 pm
I believe that to use the PropertyPlaceholderConfigurer over multiple bean definition files, you need to add the bean definition in each definition file.
November 10th, 2006 at 8:30 am
eceppda: (PropertyPlaceholderConfigurer over multiple…) No, you don’t; use the “locations” property instead of “location”.
July 20th, 2007 at 7:49 am
if you could know where you fall - you would spread some straw (there)
September 24th, 2007 at 8:46 pm
myspace [url=http://acc.csueastbay.edu/~csrm/kwiki/plugin/attachments/ITiCSE07csrmWG/Myspace.html#734881141]myspace[/url] http://acc.csueastbay.edu/~csrm/kwiki/plugin/attachments/ITiCSE07csrmWG/Myspace.html 28922356
October 2nd, 2007 at 5:03 pm
Hi,
Actually I am trying to use PropertyPlaceHolderConfigurer and as described above and in other articles but getting exception: nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not load JDBC driver class [${jdbc.driverClassName}];
The property file and xml configuration is exact same as what is mentioned in this article. Can you help what is going wrong?
Thank you.
November 8th, 2007 at 8:47 am
May be you are using BeanFactory, rather than ApplicationContext, which extends BeanFactory? ApplicationContext will detect automatically PropertyPlaceHolderConfigurer as one of it’s beans, but BeanFactory will not.
If you use bean factory, you can still use it in following way (source http://static.springframework.org/spring/docs/1.2.x/reference/beans.html)
XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource(”beans.xml”));
// create placeholderconfigurer to bring in some property
// values from a Properties file
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
cfg.setLocation(new FileSystemResource(”jdbc.properties”));
// now actually do the replacement
cfg.postProcessBeanFactory(factory);
May 14th, 2008 at 4:36 pm
Pavel your answer was just what I was looking for. Thanks!!
June 6th, 2008 at 11:30 am
Thanks, this is exactly what I needed.