This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Scala, Spring and List injections

No replies
renam00
Joined: 2008-10-13,
User offline. Last seen 1 year 22 weeks ago.
I've read that Scala object can replace dependency injections, but I didn't really understand how. If you have any reference to some example or documentation, it would be appreciated.

Thanks,

Martin

From: "Grand, Mark D" <mgrand@emory.edu>
To: Martin Renaud <mr_martin_renaud@yahoo.ca>
Sent: Fri, July 2, 2010 12:58:30 PM
Subject: RE: [scala] Scala, Spring and List injections

Have you considered using Scala objects instead of spring beans?

 

From: Martin Renaud [mailto:mr_martin_renaud@yahoo.ca]
Sent: Friday, July 02, 2010 12:00 PM
To: scala@listes.epfl.ch
Subject: [scala] Scala, Spring and List injections

 

Hi,

I'm trying to use Scala and Spring together. I'm having difficulties to inject a list created with Spring into a Scala object that expect a List.

I'm looking for the best way to acheive that.

In the Spring context file, I have this:

    <util:list id="myBeanList">
        <ref bean="myBean1" />
        <ref bean="myBean2" />
        <ref bean="myBean3" />
    </util:list>
  
 When I get this bean in the code, in either of these two ways:
 
    val o1 = context.getBean("myBeanList")
    val o2 = context.getBean("myBeanList", classOf[java.util.List[MyType]])

The returned object is, as expected, of type java.util.ArrayList

I want to inject this bean into a Scala object that expects scala.collection.immutable.List - this is the part that does not work.

   <bean id="myListContainerBean" class="my.scal.object.Wrapper">
      <property name="theList" value="myBeanList" />
   </bean>
  
Where the class is defined as follow

    class my.scal.object.Wrapper {

        @scala.reflect.BeanProperty
        var theList : List[MyType] = List()
    }


Now the question… is it possible to do such thing? How? I have the feeling that the JavaConversions package can help with that but I haven't figured out how to use it to do what I want.

I'm using Scala 2.8 RC7 with Spring 3.0.

Thanks,

-Martin

 


This e-mail message (including any attachments) is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this message (including any attachments) is strictly
prohibited.

If you have received this message in error, please contact
the sender by reply e-mail message and destroy all copies of the
original message (including attachments).


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland