Search code examples
javablueprint-osgi

blueprint properties without calling route


I'm trying to initialize some attributes with value in blueprint. However, the cm:property can only be initialized when route is called. But I want to initialize when the bean is created without calling route. What should I do?

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:config="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

    <!-- define configuration properties -->
    <cm:property-placeholder persistent-id="com.tommyqu.common" update-strategy="reload">
        <cm:default-properties>
            <cm:property name="activemq.group.name" value="edpDev" />
            <cm:property name="event.destinationQueue" value="edp-event" /> 
        </cm:default-properties>
    </cm:property-placeholder>

    <bean id="eventBean" class="com.tommyqu.EventBean">
        <property name="queueGroupName" value="${activemq.group.name}" />
        <property name="eventQueueName" value="${event.destinationQueue}" />
    </bean>
</blueprint>

Solution

  • I think it is not mandatory to declare a route but the property injection will work only if you set up a CamelContext.

    You can try to declare an empty Camel Context like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
        xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:config="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
        xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
    
        <!-- define configuration properties -->
        <cm:property-placeholder persistent-id="com.tommyqu.common" update-strategy="reload">
            <cm:default-properties>
                <cm:property name="activemq.group.name" value="edpDev" />
                <cm:property name="event.destinationQueue" value="edp-event" /> 
            </cm:default-properties>
        </cm:property-placeholder>
    
        <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <!-- No routes declared --> 
        </camelContext>
    
        <bean id="eventBean" class="com.tommyqu.EventBean">
            <property name="queueGroupName" value="${activemq.group.name}" />
            <property name="eventQueueName" value="${event.destinationQueue}" />
        </bean>
    </blueprint>
    

    In that case you don't need a route but you declare a context so that property replacement is working.