kotlin object declaration inject class

帅比萌擦擦* 提交于 2021-01-04 04:38:25

问题


i am using kotlin + springboot to build my web application. i want to create a tool class ,so i coded like above:

@Service
object XXXUtil{

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

    ...
}

but after i started the application, resTemplate cannot be injected.

kotlin.UninitializedPropertyAccessException: lateinit property 
restTemplate has not been initialized

is it because that object declaration does not allow injection or i code in a wrong way ,please help

来源:https://stackoverflow.com/questions/53845235/kotlin-object-declaration-inject-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!