Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSGi Blueprint configuration: injecting a list of bean references

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?

like image 233
Jens Avatar asked Mar 23 '23 19:03

Jens


1 Answers

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>
like image 67
vmaroli Avatar answered Apr 25 '23 05:04

vmaroli