Prioritizing Properties Files when Bridging Camel and Spring

Last week I blogged about prioritizing properties files as they are loaded by Apache Camel in the camel-context.xml. But this will not work if you use the BridgePropertyPlaceholderConfigurer to bridge Camel and Spring’s properties placeholder abilities.

We can get the same behaviour when bridging, but we have to go about it a bit differently. This time, our camel-context looks like this:

<bean id="bridgePropertyPlaceholder" name="properties" class="somepackage.PriorityBridgePropPlaceholderConfigurer">
    <property name="locations">
    <property name="ignoreResourceNotFound" value="true"/>

And the subclassed Java code looks a bit different. Because the PropertiesLoaderSupport class has most of its properties private, we have to cache the values locally in our subclass and then pass them on to the PropertiesLoaderSupport. You can specify the file encoding either in the camel-context or in the Java code. I have chosen the latter to make re-use easier.

Here’s the rest of the code. You will probably want to add your own logging.

public class PriorityBridgePropPlaceholderConfigurer extends BridgePropertyPlaceholderConfigurer {

    private Resource[] locations;
    private boolean ignoreResourceNotFound;
    private String fileEncoding = "ISO-8859-1";

    public void setLocations(Resource... locations) {
	this.locations = locations;
    public void setIgnoreResourceNotFound(boolean ignoreResourceNotFound){
	this.ignoreResourceNotFound = ignoreResourceNotFound;
    public void setFileEncoding(String fileEncoding) {
	this.fileEncoding = fileEncoding;
    protected void loadProperties(Properties props) throws IOException {
	if (this.locations != null) {
	    for (Resource location : this.locations) {
		try {
		    PropertiesLoaderUtils.fillProperties(props, new EncodedResource(location, this.fileEncoding));
		catch (IOException ex) {
		    // Resource not found when trying to open it
		    if (this.ignoreResourceNotFound && (ex instanceof FileNotFoundException || ex instanceof UnknownHostException)) {
		    else {
			throw ex;

Leave a Reply

Your email address will not be published. Required fields are marked *