【发布时间】:2016-10-14 01:39:38
【问题描述】:
我正在尝试在蓝图 1 中定义一个属性并将其用作蓝图 2 中的默认属性。
两个蓝图都将加载到同一个 Karaf OSGI 容器中,但存在于不同的包中。清单已经设置了必要的依赖信息。
这是我的 Blueprint1,它定义了我想在另一个蓝图中再次使用的属性:
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<!-- Properties for this blueprint -->
<osgix:cm-properties id="sharedProperties" persistent-id="com.foo.project" update-strategy="reload"
xmlns="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
<default-properties>
<property name="shared-property" value="value"/>
</default-properties>
</osgix:cm-properties>
<bean id="myBean"
class="com.foo.MyClass">
<property name="setting" value="{{shared-property}}"/>
</bean>
我的另一个蓝图正在尝试使用上面定义的“我的属性”:
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
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.osgi.org/xmlns/blueprint/v1.0.0
https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<!-- Load the properties from Blueprint1. Intent is to use property defined over there, here. -->
<osgix:cm-properties id="sharedProperties" persistent-id="com.foo.project"/>
<!-- Make properties defined in sharedProperties available using ${} syntax-->
<ctx:property-placeholder properties-ref="sharedProperties" />
<!-- Properties for this blueprint -->
<property-placeholder persistent-id="com.foo.project.blueprint2" update-strategy="reload"
xmlns="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
placeholder-prefix="{{{"
placeholder-suffix="}}}">
<default-properties>
<property name="my-property" value="${shared-property}"/>
</default-properties>
</property-placeholder>
<bean id="myBean"
class="com.foo.MyClass">
<property name="setting" value="{{{my-property}}}"/>
</bean>
我有一种感觉(也许只是希望)这接近正确,但有一点偏差。如果正确,我的问题可能是缺少命名空间处理程序。
【问题讨论】:
标签: spring apache-camel osgi blueprint-osgi