- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: Scala, Spring and List injections
Fri, 2010-07-02, 18:30
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
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).
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).