This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Using PropertyPlaceholder
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Using PropertyPlaceholder

Available as of Camel 2.3

Camel now provides a new PropertiesComponent in camel-core which allows you to use property placeholders when defining Camel Endpoint URIs.
This works much like you would do if using Spring's <property-placeholder> tag. However Spring have a limitation which prevents 3rd party frameworks to leverage Spring property placeholders to the fullest. See more at How do I use Spring Property Placeholder with Camel XML.

The property placeholder is generally in use when doing:

  • lookup or creating endpoints
  • lookup of beans in the Registry
  • additional supported in Spring XML (see below in examples)


The syntax to use Camel's property placeholder is to use {{key}} for example {{file.uri}} where file.uri is the property key.
You can use property placeholders in parts of the endpoint URI's which for example you can use placeholders for parameters in the URIs.


As usually Camel provides a pluggable mechanism which allows 3rd part to provide their own resolver to lookup properties. Camel provides a default implementation which is capable of loading properties from the file system, classpath or Registry. You can prefix the locations with either:

  • ref: Camel 2.4: to lookup in the Registry
  • file: to load the from file system
  • classpath: to load from classpath (this is also the default if no prefix is provided)

Defining location

The PropertiesResolver need to know a location(s) where to resolve the properties. You can define 1 to many locations. If you define the location in a single String property you can separate multiple locations with comma such as:


Configuring in Java DSL

You have to create and register the PropertiesComponent under the name properties such as:

PropertiesComponent pc = new PropertiesComponent();
context.addComponent("properties", pc);

Configuring in Spring XML

Spring XML offers two variations to configure. You can define a spring bean as a PropertiesComponent which resembles the way done in Java DSL. Or you can use the <propertyPlaceholder> tag.

<bean id="properties" class="">
    <property name="location" value="classpath:com/mycompany/"/>

Using the <propertyPlaceholder> tag makes the configuration a bit more fresh such as:

<camelContext ...>
   <propertyPlaceholder id="properties" location="com/mycompany/"/>

Using a Properties from the Registry

Available as of Camel 2.4
For example in OSGi you may want to expose a service which returns the properties as a java.util.Properties object.

Then you could setup the Properties component as follows:

   <propertyPlaceholder id="properties" location="ref:myProperties"/>

Where myProperties is the id to use for lookup in the OSGi registry. Notice we use the ref: prefix to tell Camel that it should lookup the properties for the Registry.

Examples using properties component

When using property placeholders in the endpoint URIs you can either use the properties: component or define the placeholders directly in the URI. We will show example of both cases, starting with the former.

// properties

// route

You can also use placeholders as a part of the endpoint uri:

// properties

// route

In the example above the to endpoint will be resolved to mock:result.

You can also have properties with refer to each other such as:

// properties

// route

Notice how cool.concat refer to another property.

The properties: component also offers you to override and provide a location in the given uri using the locations option:



You can also use property placeholders directly in the endpoint uris without having to use properties:.

// properties

// route

And you can use them in multiple wherever you want them:

// properties

// route

You can also your property placeholders when using ProducerTemplate for example:

template.sendBody("{{cool.start}}", "Hello World");

Example with Simple language

The Simple language now also support using property placeholders, for example in the route below:

// properties
cheese.quote=Camel rocks

// route
    .transform().simple("Hi ${body} do you think ${properties:cheese.quote}?");

You can also specify the location in the Simple language for example:

bar.quote=Beer tastes good

// route
    .transform().simple("Hi ${body}. ${properties:com/mycompany/}.");

Additional property placeholder supported in Spring XML

The property placeholders is also supported in many of the Camel Spring XML tags such as <package>, <packageScan>, <contextScan>, <jmxAgent>, <endpoint>, <routeBuilder>, <proxy> and the others.

The example below has property placeholder in the <jmxAgent> tag:

Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
<camelContext xmlns="">
    <propertyPlaceholder id="properties" location="org/apache/camel/spring/"/>

    <!-- we can use propery placeholders when we define the JMX agent -->
    <jmxAgent id="agent" registryPort="{{myjmx.port}}" disabled="{{myjmx.disabled}}"

    <route id="foo" autoStartup="false">
        <from uri="seda:start"/>
        <to uri="mock:result"/>


You can also define property placeholders in the various attributes on the <camelContext> tag such as trace as shown here:

Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
<camelContext trace="{{foo.trace}}" xmlns="">
    <propertyPlaceholder id="properties" location="org/apache/camel/spring/processor/"/>

    <template id="camelTemplate" defaultEndpoint="{{}}"/>

        <from uri="direct:start"/>
        <setHeader name="{{foo.header}}">
            <simple>${in.body} World!</simple>
        <to uri="mock:result"/>

Overriding a property setting using a JVM System Property

Available as of Camel 2.5
It is possible to override a property value at runtime using a JVM System property without the need to restart the application to pick up the change. This may also be accomplished from the command line by creating a JVM System property of the same name as the property it replaces with a new value. An example of this is given below

PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
System.setProperty("cool.end", "mock:override");
System.setProperty("cool.result", "override");

context.addRoutes(new RouteBuilder() {
    public void configure() throws Exception {


template.sendBody("direct:start", "Hello World");
template.sendBody("direct:foo", "Hello Foo");


Unit tests

See the unit tests in camel-core and camel-spring

  • SpringPropertiesComponentTest.xml
  • SpringPropertiesComponent2Test.xml
  • SpringPropertiesComponent3Test.xml
  • No labels