Search code examples
springapache-camelblueprint-osgi

How to inject properties from multiple property placeholders into java


In my camel/blueprint project i defined a property-placeholder in the blueprint.xml:

<cm:property-placeholder id="props.placeholder" persistent-id="props.blueprint">
    <cm:default-properties>
        <cm:property name="app.name" value="app-service" />
    </cm:default-properties>
</cm:property-placeholder>

With this in place i can inject the properties in java (e.g. camel routes):

@Value("${app.name}")
private String name;

Now i need to introduce a 2nd property placeholder:

<cm:property-placeholder id="container_specific.placeholder" persistent-id="container_specific.blueprint"
                         placeholder-prefix="%%{" placeholder-suffix="}%%">
    <cm:default-properties>
        <cm:property name="service.port" value="1234"/>
    </cm:default-properties>
</cm:property-placeholder>

But how to use/inject property from the 2nd holder into java? @Value("%%{service.port}%%) does not work.


Solution

  • Read the documentation: http://camel.apache.org/using-propertyplaceholder.html

    There is an example which shows how to refer to the blueprint by id, so just configure Camel to refer to those two ids

    <propertyPlaceholder id="properties" 
                         location="blueprint:props.placeholder,blueprint:container_specific.placeholder">