没有调用路由的蓝图属性

blueprint properties without calling route

我正在尝试用蓝图中的值初始化一些属性。但是,cm:property 只能在调用路由时初始化。但是我想在不调用路由的情况下创建bean时进行初始化。我该怎么办?

<?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>

我认为声明路由不是强制性的,但 属性 注入只有在您设置 CamelContext 时才会起作用。

您可以尝试像这样声明一个空的 Camel 上下文:

<?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>

在那种情况下,您不需要路由,但您声明了一个上下文,以便 属性 替换工作正常进行。