...
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)
- using Blueprint PropertyPlaceholder with Camel Properties component
- using
@PropertyInject
to inject a property in a POJO
Syntax
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.
...
Camel provides a pluggable mechanism which allows 3rd part to provide their own resolver to lookup properties. Camel provides a default implementation org.apache.camel.component.properties.DefaultPropertiesResolver
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 Registryfile:
to load the from file systemclasspath:
to load from classpath (this is also the default if no prefix is provided)blueprint:
Camel 2.7: to use a specific OSGi blueprint placeholder service
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:
...
In the example below we use the prop
prefix for the namespace http://camel.apache.org/schema/placeholder
by which we can use the prop
prefix in the attributes in the XML DSLs. Notice how we use that in the Multicast to indicate that the option stopOnException
should be the value of the placeholder with the key "stop".
...
When Testing with Camel and using the Properties component, you may want to be able to provide the properties to be used from directly within the unit test source code.
This is now possible from Camel 2.10 onwards, as the Camel test kits, eg CamelTestSupport
class offers the following methods
- useOverridePropertiesWithPropertiesComponent
- ignoreMissingLocationWithPropertiesComponent
So for example in your unit test classes, you can override the useOverridePropertiesWithPropertiesComponent
method and return a java.util.Properties
that contains the properties which should be preferred to be used.
...
Code Block |
---|
@PropertyInject(value = "myTimeout", defaultValue = "5000") private int timeout; |
See Also
- Properties component