@Autowired in the constructor of the Scala class

I have a simple question: how could I use spring @Autowired in the constructor of this Scala class?

class MessageMBeanExporter(messageDirectory: MessageDirectory) extends MBeanExporter with SmartLifecycle { ..... } 
+6
source share
2 answers

I have not tried, but according to this and this link , from 2.8+ you can do:

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

I added @Autowired support in the Scala object constructor to the spring - scala project. It is only (at the time of writing) in the night shot.

It allows you to do

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

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

+2
source

Source: https://habr.com/ru/post/950722/


All Articles