一段時間以來一直在使用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>
謝謝,但我確實是這樣。問題是在運行時spring不能解析xml。目前的春天版本似乎沒有支持這個東西?! – dermoritz