title: Kotlin with Spring DI: lateinit property has not been initialized
body: <p>I don't get Spring-based setter dependency injection in Kotlin to work as it always terminates with the error message "lateinit property api has not been initialized". I could reduce the problem to the following scenario: There is an interface</p>
  
  <pre><code>interface IApi {
    fun retrieveContent(): String
  }
  </code></pre>
  
  <p>which is implemented by</p>
  
  <pre><code>class Api : IApi {
      override fun retrieveContent() = "Some Content"
  }
  </code></pre>
  
  <p>I want to use the implementation in another class where the dependency injection is supposed to take place:</p>
  
  <pre><code>@Component
  class SomeController {
      @Autowired lateinit var api: IApi
      fun printReceivedContent() {
          print(api.retrieveContent())
      }
  }
  </code></pre>
  
  <p>However, the application terminates with the above-mentioned error message. My Spring config looks as follows:</p>
  
  <pre><code>@Configuration
  open class DIConfig {
      @Bean
      open fun getApiInstance(): IApi = Api()
  }
  </code></pre>
  
  <p>In the main function I load the application context and call the method:</p>
  
  <pre><code>fun main(args: Array&lt;String&gt;) {
      val context = AnnotationConfigApplicationContext()
      context.register(DIConfig::class.java)
      context.refresh()
  
      val controller = SomeController()
      controller.printReceivedContent()
  }
  </code></pre>
  
  <p>What is the problem here?</p>