Kotlin对象声明注入类

时间:2018-12-19 05:43:29

标签: spring-boot kotlin

我正在使用kotlin + springboot来构建我的Web应用程序。 我想创建一个工具类,所以我像上面这样编码:

@Service
object XXXUtil{

    @Autowired
    lateinit var restTemplate: RestTemplate
    @Autowired
    lateinit var objectMapper: ObjectMapper

    ...
}

但是我启动应用程序后,无法注入resTemplate。

kotlin.UninitializedPropertyAccessException: lateinit property 
restTemplate has not been initialized

是因为对象声明不允许注入或我以错误的方式编写代码,请帮助

0 个答案:

没有答案
相关问题