javaxmlosgiapache-karafblueprint

How to use a ArrayList as a bean in blueprint xml?


I believe the name of the thread is self explanatory. I will share with my tryouts and what kind of faults I'm occurring. Top of my Xml file looking like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:util="http://www.springframework.org/schema/util"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
<bean id="someBean" class="com.someClass"/>
<bean id="someBean1" class="com.someClass"/>

<bean id="messageFilterList" class="java.util.ArrayList">
 <constructor-arg>
  <list value-type="com.someClass">
   <ref bean="someBean"/>
  </list>
 </constructor-arg>
</bean>
Fault:
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://www.osgi.org/xmlns/blueprint/v1.0.0":constructor-arg}'. One of '{"http://www.osgi.org/xmlns/blueprint/v1.0.0":description, "http://www.osgi.org/xmlns/blueprint/v1.0.0":argument, "http://www.osgi.org/xmlns/blueprint/v1.0.0":property, WC[##other:"http://www.osgi.org/xmlns/blueprint/v1.0.0"]}' is expected.

I've also tried to every mix of this one which is, using argument and property instead of constructor-arg even if doesn't make that much of sense for me. I've also tried to initiate with factory-method=add to add those object via method not constructor, but still got more less same faults, which were caused by org.xml.sax.SAXParseException.

2.

<util:list>
       <ref bean="idOfBeanI'veTriedToGet"/>
</util:list>

With this solution my application just stopped working without any explanation. I'm doing camel project so there was any other info into karaf log instead of stopped routes.

If anyone knows how to properly configurate object with an ArrayList I would be thankful to see the solution.

Thanks in advance and have a nice day :)


Solution

  • You are using the elements incorrectly, should be this way:

    <bean id="messageFilterList" class="java.util.ArrayList">
        <argument>
            <list value-type="com.someClass">
                <ref component-id="someBean"/>
            </list>
        </argument>
    </bean>
    

    Problems:

    1. You should use <argument> to specify constructor arguments for a bean.

    2. You should use <ref component-id="someBean"/> to reference the someBean and add it to the ArrayList.