title: Spring: Injecting a Scala List
body: <p>This can be done using a converter wrapper:</p>
  
  <pre class="lang-scala prettyprint-override"><code>import scala.collection.JavaConversions._
  
  object ListConverter {
  
    def toScalaList( jlist: java.util.List[AnyRef] ) = {
      jlist.toList
    }
  }
  </code></pre>
  
  <p>which uses a <code>implicit def asScalaBuffer</code> in <code>JavaConversions</code> to return a Scala List. Then I can make the list injectable as:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="someItems" class="my.package.ListConverter" factory-method="toScalaList"&gt;
      &lt;constructor-arg type="java.util.List"&gt;
          &lt;util:list&gt;
              &lt;ref bean="itemOne"/&gt;
              &lt;ref bean="itemTwo"/&gt;
          &lt;/util:list&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p><strong>I would like to find a cleaner way to do this</strong></p>
  
  <p>I can't really use <code>JavaConversions</code> directly as a static factory call:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="someItems" class="scala.collection.JavaConversions" factory-method="asScalaBuffer"&gt;...&lt;/bean&gt;
  </code></pre>
  
  <p>Since an <code>implicit def</code> is not really a static method in a Java universe.</p>
  
  <p><em>P.S. To get it out of the way.. I know there are a lot of annotation driven config lovers, but I am not one of them, and that is not a solution I am looking for: <strong>I like my XML for Spring configs</strong>, and <strong>I like Spring to DI Scala</strong></em></p>