【问题标题】:Share a Property between two blueprints在两个蓝图之间共享一个属性
【发布时间】: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


    【解决方案1】:

    通过使用“default-properties”标签,您可以重新定义值。从第二个项目中删除。另外,我建议从两者中删除默认属性并使用外部化的 cfg 文件,这样您在启动时就不会出现竞争条件。

    删除这个:

    <default-properties>
        <property name="my-property" value="${shared-property}"/>
    </default-properties>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-31
      • 1970-01-01
      • 2015-07-30
      • 2017-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多