@Autowired 在 Scala 类的构造函数上 [英] @Autowired on a constructor of a Scala class

查看:35
本文介绍了@Autowired 在 Scala 类的构造函数上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题,如何在这个 Scala 类的构造函数上使用 spring @Autowired?

I have a simple question, How could I use spring @Autowired on a constructor of this Scala class?

class MessageMBeanExporter(messageDirectory: MessageDirectory) extends MBeanExporter with SmartLifecycle {
      .....
}

推荐答案

我没试过,但是根据this此链接,从 2.8+ 你可以这样做:

I haven't tried it, but according to this and this link, from 2.8+ you could do:

class MessageMBeanExporter @Autowired() (messageDirectory: MessageDirectory) extends MBeanExporter with SmartLifecycle {
      .....
}

这篇关于@Autowired 在 Scala 类的构造函数上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆