The Spring configuration files can include values from your properties files. You can easily customize this so that you can take control when the key and or the value of a property is requested. To do so, you must first tell Spring the location of your properties file:
<beans>
<bean class="com.mycompany.MyPropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:my.properties</value>
</property>
</bean>
...
Next you must create the class:
com.mycompay.MyPropertyPlaceholderConfigurer:
package com.mycompany;
import java.util.Properties;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import com.adobe.hs.spdf.common.PropReader;
public class MyPropertyPlaceholderConfigurer extends
PropertyPlaceholderConfigurer {
// process the key and then return the associated value...
protected String resolvePlaceholder(String placeholder, Properties props) {
String value = process-the-key-and-lookup-the-value;
return value;
}
}
Finally, you can use the Spring’s ${...} notation to reference values from your properties file. e.g.,
November 4, 2008 at 12:51 pm |
Very helpful. Especially the class writeup.
August 4, 2010 at 9:10 am |
For java queries, you can refer : http://pragyarawal.blogspot.com
July 25, 2011 at 2:46 pm |
[...] http://note19.com/2007/08/01/spring-configuration-with-property-files/ This entry was posted in Uncategorized. Bookmark the permalink. ← Installing memcached [...]