繁体   English   中英

Kotlin 自动装配问题 - 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,以及“它”何时被初始化?

@Stav Shamir 的评论使我得出了这个决议。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM