Properties

Since Camel 2.3

The properties component is used for property placeholders in your Camel application, such as endpoint URIs. It is not a regular Camel component with producer and consumer for routing messages. However, for historical reasons it was named PropertiesComponent and this name is commonly known so we keep using it.

See the Property Placeholder documentation for general information on using property placeholders in Camel.

The properties component requires to load the properties (key=value pairs) from an external source such as .properties files. The component is pluggable, and you can configure to use other sources or write a custom implementation (for example to load from a database).

Defining location of properties files

The properties component needs to know a location(s) where to resolve the properties. You can define one to many locations. Multiple locations can be separated by comma such as:

pc.setLocation("com/mycompany/myprop.properties,com/mycompany/other.properties");

You can mark a location to be optional, which means that Camel will ignore the location if not present:

pc.setLocations(
    "com/mycompany/override.properties;optional=true"
    "com/mycompany/defaults.properties");

Using system and environment variables in locations

The location now supports using placeholders for JVM system properties and OS environments variables.

For example:

location=file:${karaf.home}/etc/foo.properties

In the location above we defined a location using the file scheme using the JVM system property with key karaf.home.

To use an OS environment variable instead you would have to prefix with env:. You can also prefix with env., however this style is not recommended because all the other functions use colon.

location=file:${env:APP_HOME}/etc/foo.properties

Where APP_HOME is an OS environment.

Some OS’es (such as Linux) do not support dashes in environment variable names, so here we are using APP_HOME. But if you specify APP-HOME then Camel 3 will automatic lookup the value as APP_HOME (with underscore) as fallback.

You can have multiple placeholders in the same location, such as:

location=file:${env:APP_HOME}/etc/${prop.name}.properties

Defining location of properties files 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. Or you can use the <propertyPlaceholder> tag.

<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
    <property name="location" value="classpath:com/mycompany/myprop.properties"/>
</bean>

Using the <propertyPlaceholder> allows to configure this within the <camelContext> tag.

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

For fine grained configuration of the location, then this can be done as follows:

<camelContext>
  <propertyPlaceholder id="myPropertyPlaceholder">
    <propertiesLocation
      resolver = "classpath"
      path     = "com/my/company/something/my-properties-1.properties"
      optional = "false"/>
    <propertiesLocation
      resolver = "classpath"
      path     = "com/my/company/something/my-properties-2.properties"
      optional = "false"/>
    <propertiesLocation
      resolver = "file"
      path     = "${karaf.home}/etc/my-override.properties"
      optional = "true"/>
   </propertyPlaceholder>
</camelContext>

Spring Boot Auto-Configuration

The component supports 10 options, which are listed below.

Name Description Default Type

camel.component.properties.auto-discover-properties-sources

Whether to automatically discovery instances of PropertiesSource from registry and service factory.

true

Boolean

camel.component.properties.default-fallback-enabled

If false, the component does not attempt to find a default for the key by looking after the colon separator.

true

Boolean

camel.component.properties.encoding

Encoding to use when loading properties file from the file system or classpath. If no encoding has been set, then the properties files is loaded using ISO-8859-1 encoding (latin-1) as documented by java.util.Properties#load(java.io.InputStream)

String

camel.component.properties.environment-variable-mode

Sets the OS environment variables mode (0 = never, 1 = fallback, 2 = override). The default mode (override) is to use OS environment variables if present, and override any existing properties. OS environment variable mode is checked before JVM system property mode

2

Integer

camel.component.properties.ignore-missing-location

Whether to silently ignore if a location cannot be located, such as a properties file not found.

false

Boolean

camel.component.properties.initial-properties

Sets initial properties which will be used before any locations are resolved. The option is a java.util.Properties type.

String

camel.component.properties.location

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.

String

camel.component.properties.override-properties

Sets a special list of override properties that take precedence and will use first, if a property exist. The option is a java.util.Properties type.

String

camel.component.properties.properties-parser

To use a custom PropertiesParser. The option is a org.apache.camel.component.properties.PropertiesParser type.

String

camel.component.properties.system-properties-mode

Sets the JVM system property mode (0 = never, 1 = fallback, 2 = override). The default mode (override) is to use system properties if present, and override any existing properties. OS environment variable mode is checked before JVM system property mode

2

Integer