Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个简单的问题,我如何在这个 Scala 类的构造函数上使用 spring @Autowired?
class MessageMBeanExporter(messageDirectory: MessageDirectory) extends MBeanExporter with SmartLifecycle { ..... }
我没有尝试过,但根据这个和这个链接,你可以从 2.8+ 开始:
class MessageMBeanExporter @Autowired() (messageDirectory: MessageDirectory) extends MBeanExporter with SmartLifecycle { ..... }
我在 spring-scala 项目的 Scala 对象的构造函数中添加了对 @Autowired 的支持。这仅在夜间快照中(在撰写本文时)。
这可以让你做
@Component @Autowired class Service(dep : Dependency) { }
https://github.com/spring-projects/spring-scala