简体   繁体   English

使用Spring和Scala进行多依赖注入的语法是什么?

[英]What's the syntax for multiple dependency injection using Spring and Scala?

I'm creating a new application using Akka, Scala and Spring. 我正在使用Akka,Scala和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? 由于语法与Java不同,有人可以告诉我多个DI的外观如何吗?

Spring 4 MVC with Scala Spring 4 MVC与Scala

akka-scala-spring 阿卡-阶弹簧

Converting a Java Spring application to Scala 将Java Spring应用程序转换为Scala

Example of single DI: 单个DI的示例:

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

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. 不幸的是,我还没有在Scala中使用Spring,但是如果@Autowired类似于Google Guice的@Inject ,并且看起来非常相似,那么这应该是您在类文件中所需的全部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM