2017-06-02 18 views
0

我試圖將存儲在Karaf中的屬性注入到我的駱駝/彈簧服務中。到目前爲止,我試圖按照Fuse documentationSpring中記錄的方式注入屬性。 但兩者都顯得過時:當前的Spring版本(Fuse 6.3使用3.2.16)無法解析osgix:cm-properties如何使用OSGI/Karaf ConfigurationAdminService中的屬性和Spring依賴注入

另一方面,Apache Aries似乎有一些可以使用的東西。該aries-blueprint-spring功能包含兩個包:

  • aries.blueprint.spring
  • aries.blueprint.spring.extender

我發現指向此捆舊的用戶列表後。但我找不到任何文檔或例子。我們只需要注入屬性。

回答

2

一段時間以來一直在使用OSGi Service Compendium,下面是我的一個項目的一些摘錄,希望它有所幫助。

重要的是綱要命名空間的聲明,它的前綴osgix

還要注意持續-ID的相同的情況聲明在Karaf配置文件被定義爲內部創建你的容器實例的etc目錄。

現在有春天財產佔位指osgix性聲明和propertyPlaceholder內CamelContext。如果你想訪問外部的屬性 - $ {propName}和內部 - {{propName}} CamelContext,兩者都是必需的。

駱駝語境語法外訪問屬性是$ {propertyName的}
要訪問駱駝語境syntnax內部屬性是{{propertyName的}}


<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" xmlns:ctx="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd  
    http://camel.apache.org/schema/spring    http://camel.apache.org/schema/spring/camel-spring.xsd 
    http://www.springframework.org/schema/osgi   http://www.springframework.org/schema/osgi/spring-osgi.xsd 
    http://www.springframework.org/schema/osgi-compendium  http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd 
    http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsd"> 



    <!-- A. Configuration Management --> 
    <osgix:cm-properties id="cachingServicesProp" persistent-id="com.fsafrica.cachingservices.cm"> 
     <prop key="amqBrokerUrl">tcp://localhost:61616</prop> 
     <prop key="amqUsername">admin</prop> 
     <prop key="amqPassword">admin</prop> 
     <prop key="queueName">jms/SRK_CACHE_QUEUE</prop> 
    </osgix:cm-properties> 

    <!-- Required for resolving properties for Beans outside CamelContext --> 
    <ctx:property-placeholder properties-ref="cachingServicesProp" /> 



    <!-- B. ActiveMQ --> 
    <bean class="org.apache.activemq.camel.component.ActiveMQComponent" id="activemq"> 
     <property name="brokerURL" value="${amqBrokerUrl}" /> 
     <property name="userName" value="${amqUsername}" /> 
     <property name="password" value="${amqPassword}" /> 
    </bean> 



    <camelContext id="CC-CachingMain" xmlns="http://camel.apache.org/schema/spring"> 

     <!-- Required for resolving properties inside CamelContext --> 
     <propertyPlaceholder id="properties" location="ref:cachingServicesProp"/> 



     <!-- JMS INTERFACE --> 
     <route id="Route-JMSMasterData"> 

      <from uri="activemq:queue:{{queueName}}?transacted=false" /> 

      <log message="#### After putting some data in the Queue (jms/SRK_CACHE_QUEUE) you should be able read this text on Karaf console" /> 

     </route> 

    </camelContext> 

</beans> 
+0

謝謝,但我確實是這樣。問題是在運行時spring不能解析xml。目前的春天版本似乎沒有支持這個東西?! – dermoritz