问题
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