The Artima Developer Community
Sponsored Link

Java Buzz Forum
Spring PropertyPlaceholderConfigurer: A nice clean way to share

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Spring PropertyPlaceholderConfigurer: A nice clean way to share Posted: Sep 20, 2004 5:20 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: Spring PropertyPlaceholderConfigurer: A nice clean way to share
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement
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!

Read: Spring PropertyPlaceholderConfigurer: A nice clean way to share

Topic: Performance Testing, Lean Management Previous Topic   Next Topic Topic: Dissent is not un-American

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use