【发布时间】:2015-04-21 09:50:41
【问题描述】:
我刚刚开始学习 OSGi 和 camel,我正在研究一些已经实现的服务。我有一个在 OSGi 蓝图的帮助下配置为在 Servicemix 上运行的包,有点像这样:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/blueprint/core"
xsi:schemaLocation="
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd">
<camelContext id="ctx1"
xmlns="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<propertyPlaceholder location="properties/config.properties"/>
<routeBuilder ref="..." />
</camelContext>
目前,config.properties 位于捆绑包内,但我正在尝试将其外部化。
所以,我将我的蓝图更改为:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/blueprint/core"
xsi:schemaLocation="
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd">
<camelContext id="ctx1"
xmlns="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<propertyPlaceholder location="${karaf.home}/etc/config.properties"/>
<routeBuilder ref="..." />
</camelContext>
... 这个配置工作得很好。
我面临的问题是,该属性文件还通过 java.util.properties 在多个位置使用,该文件作为一个简单文件加载到 util 文件的静态代码块中。
我可以在我的 Java 代码(骆驼代码除外)中使用骆驼上下文中加载的属性吗?
如果这是不可能的,那么我应该如何加载位于 servicemix 类路径中的属性文件,以便在骆驼上下文和 java 代码中使用,在我当前的实现中以最少的代码更改。 p>
【问题讨论】:
标签: java apache-camel apache-karaf blueprint-osgi apache-servicemix