4

I am trying to inject a list of beans in a list property in my blueprint.xml (similar to what you would do in Spring configuration):

blueprint.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>

AnotherClass:

public class AnotherClass {
   private List<MyClass> myClasses;

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

I had a look at the Blueprint XML schema and the R4.2 enterprise spec (which we are using) and found nothing suitable. But this is just such an obvious use case that I can't believe that this is not possible.

Any suggestions what I am missing here and how to do this?

Jens
  • 20,533
  • 11
  • 60
  • 86

2 Answers2

6

I came across same issue and found an answer here. In ref element, change from bean to component-id.

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

<bean id="anotherBean" class="AnotherClass">
  <property name="myClasses">
    <list>
      <ref component-id="myBean" />
    </list>
  </property>
</bean>
vmaroli
  • 613
  • 9
  • 21
1

The list element should actually work natively provided you are not suffering from a malformed xml problem as found in the example code (assuming a typo for the missing slash in the closing list tag).

Here is a very good slide deck with described usage:

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

[original suggestion below may still work but should not be required]

However, you should still be able to use other spring schema.

Try adding the util schema:

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

and then namespacing the list element:

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

(this works seamlessly in spring because the beans namespace imports several other namespaces, including "util", automatically)

Ray
  • 1,324
  • 10
  • 18