title: Can I use @autowire (spring-context) for a kotlin desktop application?
body: <p>I'm trying to use Spring DI for kotlin-javafx desktop app but Spring doesn't inject a beans to lateinit property.</p>
  
  <p>Here is my starter class</p>
  
  <pre><code>package ui
  
  @Component
  class Starter : Application() {
  
      override fun start(primaryStage: Stage?) {
  
          val root : Parent = FXMLLoader.load(javaClass.getResource("/view/main.fxml"))
          primaryStage?.title = "Title"
          primaryStage?.scene = Scene(root)
          primaryStage?.show()
      }
  
      companion object {
          @JvmStatic
          fun main(args: Array&lt;String&gt;) {
              AnnotationConfigApplicationContext(SpringConfig::class.java)
  
              launch(Starter::class.java, *args)
          }
      }   
  
  }
  </code></pre>
  
  <p>Here is my Spring-config class</p>
  
  <pre><code>package config
  
  @Configuration
  @ComponentScan(basePackages = arrayOf("domain", "ui"))
  open class SpringConfig {   
  
  }
  </code></pre>
  
  <p>Here is my bean that I want to inject</p>
  
  <pre><code>package domain
  
  @Component
  open class State {
  
      private val coinsState = mapOf(Coin.SYS to CoinState(Coin.SYS))
  
      fun setActiveForCoin(coin : Coin, isActive : Boolean) {
          val coin = coinsState[coin]
          if (coin == null) throw IllegalArgumentException("Coin $coin does not exist!")
          coin.isActive = isActive
      }
  }
  </code></pre>
  
  <p>and finally my javafx controller which should receive a bean (instance of the controller created automatically, I just setup his name in .fxml file)</p>
  
  <pre><code>package ui.controller
  
  @Component
  class CoinController {
  
      @Autowired
      private lateinit var state : State
  
      @FXML
      fun showConfirmDialog(actionEvent: ActionEvent) {
          println(state)
  
          val alert = Alert(AlertType.CONFIRMATION)
          alert.title = "Confirmation Dialog"
          alert.headerText = "Look, a Confirmation Dialog"
          //alert.contentText = "Are you ok with this?"
  
          val result = alert.showAndWait()
          if (result.get() == ButtonType.OK) {
              // ... user chose OK
          } else {
              // ... user chose CANCEL or closed the dialog
          }
      }
  
  }
  </code></pre>