Properties

Overview

Property endpoints allow you to resolve the address for an endpoint using a property placeholder. Property placeholders can be created using a properties file, OSGi properties, the OSGi registry, Spring beans, or as part of the route definition.

The property placeholder is typically used when:

  • looking up or creating endpoints

  • looking up beans in the Registry

  • using Blueprint's PropertyPlaceholder with Apache Camel's Properties component

  • using property placeholder in many of Spring's Camel xml tags, such as package, packageScan, contextScan, jmxAgent, endpoint, routeBuilder, proxy, and others

URI format

The URI format for a property endpoint is:

properties:key[?options]

Where key is the key for the property to lookup.

Options

Table 67, “Properties options” describes the options for a property endpoint.

Table 67. Properties options

NameTypeDescription
cache boolean

Whether or not to cache loaded properties.

Defaults to true.

locations String

A list of locations to load properties. You can use comma to separate multiple locations. This option will override any default locations and only use the locations from this option.

Defaults to null.

ignoreMissingLocation boolean

Apache Camel 2.10 onwards: Whether to silently ignore if a location cannot be located, such as a properties file not found.

Defaults to false.

propertyPrefix String

Apache Camel 2.9 onwards: Optional prefix prepended to property names before resolution.

Defaults to null.

propertySuffix String

Apache Camel 2.9 onwards: Optional suffix appended to property names before resolution.

Defaults to null.

fallbackToUnaugmentedProperty boolean

Apache Camel 2.9 onwards: If true, first attempt resolution of property name augmented with propertyPrefix and propertySuffix before falling back to the plain property name specified. If false, only the augmented property name is searched.

Defaults to true.

prefixToken String

Apache Camel 2.9 onwards: The token to indicate the beginning of a property token.

Defaults to {{.

suffixToken String

Apache Camel 2.9 onwards: The token to indicate the end of a property token.

Defaults to {{.


[Note]Note

You can resolve a property from any Java code by using the resolvePropertyPlaceholders method on the CamelContext.

Bridging Spring and Apache Camel property placeholders

Available as of Apache Camel 2.10.

The Spring Framework does not allow third-party frameworks, such as Apache Camel, to seamlessly hook into the Spring property placeholder mechanism. However, you can easily bridge Spring and Camel by declaring a Spring bean with the type org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer, which is a Spring org.springframework.beans.factory.config.PropertyPlaceholderConfigurer type.

To bridge Spring and Camel you must define a single bean as shown here:

<!-- bridge spring property placeholder with Camel -->
<!-- you must NOT use the <context:property-placeholder at the same time, only this bridge bean -->
<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
  <property name="location" value="classpath:org/apache/camel/component/properties/cheese.properties"/>
</bean>
[Important]Important

You must not use the spring context:property-placeholder namespace at the same time.

After declaring this bean, you can define property placeholders using either the Spring style or the Camel style within the <camelContext> tag as shown here:

<!-- a bean that uses Spring property placeholder -->
<!-- the ${hi} is a spring property placeholder -->
<bean id="hello" class="org.apache.camel.component.properties.HelloBean">
  <property name="greeting" value="${hi}"/>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
  <!-- in this route we use Camels property placeholder {{ }} style -->
  <route>
    <from uri="direct:{{cool.bar}}"/>
    <bean ref="hello"/>
    <to uri="{{cool.end}}"/>
  </route>
</camelContext>

Notice how the hello bean uses pure Spring property placeholders via the ${ } notation. And in the Camel routes, we use the Camel placeholder notation with {{ }}.

See also

Properties Component.