【发布时间】:2017-01-09 11:28:28
【问题描述】:
这是我得到的:
@Component
class FooController {
fun createFoo() {
val foo = FooEntity()
foo.name = "Diogo"
fooRepository.save(foo)
}
@Autowired
internal lateinit var fooRepository: FooRepository
}
在尝试调用createFoo() 时,我收到以下错误:
kotlin.UninitializedPropertyAccessException: lateinit property fooRepository has not been initialized
我认为在顶部添加 @Component 会使 Spring 发现我的类,从而使 @Autowired 工作,但也许我弄错了?
【问题讨论】:
-
还可以看看使用 Spring 在 Kotlin 中注入 bean 的不同方法:stackoverflow.com/questions/35479631/…
标签: dependency-injection spring-boot kotlin