Kotlin Autowired 问题 - lateinit (obv)

Kotlin Autowired problems - lateinit (obv)

我对 kotlin 比较陌生,无法理解 spring 自动装配

kotlin.UninitializedPropertyAccessException: lateinit property applicationContext has not been initialized

我在 运行 这个:

时得到了上面的错误
@SpringBootTest
internal class MeterResourceAdapterTest () {

    @Autowired
    private lateinit var applicationContext: ApplicationContext

@Test
    fun toMeterReadingResourceList() {
        print(applicationContext.applicationName)
.....//I hope my implementation can be ignored
}

这是怎么回事?顺便说一句,为什么需要 lateinit,'it' 何时初始化?

@Stav Shamir 的评论让我做出了这个决定。

我不能确定是什么原因造成的,但几乎可以肯定这与我 pom.xml 中的旧版本 junit 有关。当我通过初始化程序创建一个新项目时,将该 pom 的内容( < dependencies/ > )复制到我的 pom 中;一切顺利