简体   繁体   中英

@Autowired on a constructor of a Scala class

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 {
      .....
}

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 {
      .....
}

I've added support for @Autowired on the constructor of a Scala object into the spring-scala project. This is only (at time of writing) in the nightly snapshot.

This allows you to do

@Component
@Autowired
class Service(dep : Dependency) { }

https://github.com/spring-projects/spring-scala

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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