1

I'm creating a new application using Akka, Scala and Spring. However all the examples I found online show a single dependency being injected. Since the syntax is different from Java, could anyone tell me what'd it look like with multiple DI?

Spring 4 MVC with Scala

akka-scala-spring

Converting a Java Spring application to Scala

Example of single DI:

class HelloWorldController @Autowired() (nameService: Name) {

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
  • Have you had a look at this SO question: [spring/scala: Possible to autowire bean dependencies?](http://stackoverflow.com/questions/25336368/spring-scala-possible-to-autowire-bean-dependencies) ? – riccardo.cardin Sep 18 '15 at 05:59
  • @riccardo.cardin I just did. How's it relevant to what I'm asking? It has no mention of multiple `@Autowired` annotations. – Abhijit Sarkar Sep 18 '15 at 06:09
  • Sorry, I have picked the wrong link :( Try this one [How to use Spring Autowired (or manually wired) in Scala object?](http://stackoverflow.com/questions/8344224/how-to-use-spring-autowired-or-manually-wired-in-scala-object) – riccardo.cardin Sep 18 '15 at 07:17
  • @riccardo.cardin Please read my question again, it's very specific. If you don't understand, don't answer but stop posting useless links. – Abhijit Sarkar Sep 18 '15 at 09:52
  • Ok, it is possibile that I do not understand your question, but if you have look at link I've posted you, you will see that you can't use the `@Autowired` directly into the constructor in Scala. You've to declare each entity that you want to be injected inside the body of the class and put the annotation over each. – riccardo.cardin Sep 18 '15 at 10:39

1 Answers1

2

I would start by simply adding parameters to the autowired argument list:

class HelloWorldController @Autowired() (service1: Foo, service2: Bar)

Unfortunately, I haven't used Spring in Scala yet, but if @Autowired is anything like Google Guice's @Inject - and it looks pretty similar - then this should be all you need in your class file.

Rushing
  • 126
  • 4
  • You're right, I eventually had a chance to test it out. See [FeignServiceInterpreter.scala](https://github.com/asarkar/feign/blob/master/app/org/abhijitsarkar/feign/service/FeignServiceInterpreter.scala) – Abhijit Sarkar Dec 15 '16 at 00:13