【问题标题】:OSGi Blueprint configuration: injecting a list of bean referencesOSGi 蓝图配置:注入 bean 引用列表
【发布时间】:2013-05-24 23:46:16
【问题描述】:

我正在尝试在我的 blueprint.xml 的列表属性中注入一个 bean 列表(类似于您在 Spring configuration 中所做的):

蓝图.xml:

<blueprint
  xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
    http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<bean id="myBean" class="MyClass" />

<bean id="anotherBean" class="AnotherClass">
  <property name="myClasses">
    <list>
      <ref bean="myBean" />
    <list>
  </property>
</bean>

</blueprint>

另一个类:

public class AnotherClass {
   private List<MyClass> myClasses;

   public void setMyClasses(List<MyClass> classes) {
     this.myClasses = classes;
   }
}

我查看了Blueprint XML schema 和R4.2 enterprise spec(我们正在使用)并没有找到合适的。但这只是一个如此明显的用例,我无法相信这是不可能的。

任何建议我在这里缺少什么以及如何做到这一点?

【问题讨论】:

    标签: java osgi blueprint-osgi


    【解决方案1】:

    我遇到了同样的问题并找到了答案here。在 ref 元素中,从 bean 更改为 component-id。

    <bean id="myBean" class="MyClass" />
    
    <bean id="anotherBean" class="AnotherClass">
      <property name="myClasses">
        <list>
          <ref component-id="myBean" />
        </list>
      </property>
    </bean>
    

    【讨论】:

      【解决方案2】:

      如果您没有遇到示例代码中出现的格式错误的 xml 问题(假设结束列表标记中缺少斜杠的错字),列表元素实际上应该可以在本地工作。

      这是一个非常好的幻灯片,上面有描述的用法:

      http://www.slideshare.net/gnodet/osgi-blueprint-services-1622424

      [下面的原始建议可能仍然有效,但不应该是必需的]

      但是,您仍然应该能够使用其他 spring 模式。

      尝试添加 util 架构:

      xmlns:util="http://www.springframework.org/schema/util"
      

      然后为列表元素命名空间:

      <util:list>
          <ref bean="myBean" />
      </util:list>
      

      (这在 spring 中可以无缝运行,因为 beans 命名空间会自动导入其他几个命名空间,包括“util”)

      【讨论】:

        猜你喜欢
        • 2013-07-31
        • 1970-01-01
        • 2013-07-09
        • 2017-09-22
        • 2012-11-22
        • 1970-01-01
        • 2014-08-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多