[英]How to use properties from OSGI/Karaf ConfigurationAdminService with Spring dependency injection
我試圖將存儲在Karaf中的屬性注入到我的Camel / Spring-Service中。 到目前為止,我試圖以Fuse文檔和Spring中介紹的方式注入屬性。 但是兩者似乎都已經過時了: osgix:cm-properties
不能被當前的Spring版本解析(保險絲6.3使用3.2.16)。
另一方面,Apache Aries似乎有一些現在可以使用的東西。 aries-blueprint-spring
功能包含兩個捆綁包:
我發現一個舊的用戶列表帖子指向此捆綁包。 但我找不到任何文檔或使用此示例。 我們只需要注入屬性。
一段時間以來一直在使用OSGi Service Compendium,以下是我的一個項目的摘錄,希望對您有所幫助。
重要的是綱要名稱空間的聲明及其前綴osgix
還要注意,與在容器實例的etc目錄中創建的Karaf配置文件中必須定義的持久化ID聲明相同。
現在,Spring 屬性占位符引用了CamelContext中的osgix屬性聲明和propertyPlaceholder 。 如果要訪問$ {propName}外部和內部{{propName}} CamelContext內的屬性,則兩者都是必需的。
要訪問駱駝語境之外的屬性,語法為$ {propertyName}
要訪問Camel Context內部語法的屬性是{{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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.