0

我正在使用 fuse 6.0 和 activemq 5.8。与其在每个 bundle 中定义 activemq 可池连接工厂,不如在一个公共 bundle 中定义并将其公开为 osgi 服务。我在 FUSE_HOME/etc 中创建了蓝图文件并打开了这样的 osgi 服务。

  <osgix:cm-properties id="prop" persistent-id="xxx.xxx.xxx.properties" /> 

    <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="${xxx.url}" />
            <property name="userName" value="${xxx.username}" />
            <property name="password" value="${xxx.password}" />
        </bean>

<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
    <property name="maxConnections" value="${maxconnections}" />
    <property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>

<service ref="pooledConnectionFactory" interface="javax.jms.ConnectionFactory"> 
    <service-properties> 
        <entry key="name" value="localhost"/> 
    </service-properties> 
</service> 

当我尝试在这样的蓝图文件和 spring 文本文件中访问此服务时

<reference id="pooledConnectionFactory" interface="javax.jms.ConnectionFactory"/>
bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
        <property name="connectionFactory" ref="pooledConnectionFactory"/>
        <property name="concurrentConsumers" value="${xxx.concurrentConsumers}"/>
    </bean>
    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="configuration" ref="jmsConfig"/>
    </bean>

但我在捆绑启动期间得到了以下预期。

添加连接 ID 失败:PLNL6237-55293-1401929434025-11:1201,原因:java.lang.SecurityException:用户名 [null] 或密码无效。

我什至在我的包中定义了纲要定义。

我怎么解决这个问题?任何帮助表示赞赏。我在网上找到了这个https://issues.apache.org/jira/i#browse/SM-2183 我需要升级吗?

4

1 回答 1

0

在我看来,您使用的属性占位符不正确。首先,您应该知道 osgix:cm-properties 仅公开您指定的持久 id 处的属性。您可以将其视为 java.util.Properties 对象,甚至将其作为一个对象注入到 bean 中。然而,这确实意味着它不会尝试解析属性。

要解析属性,请使用 spring 的属性占位符配置器。

 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="properties" ref="prop"/>
 </bean>

PS cm-properties的persistent id是文件名,不包括文件类型。最后你不需要 .properties 。

于 2014-06-08T16:36:53.160 回答