Kotlin lateinit Autowired issue in spring boot

I’m not able to get bean in spring boot with autowired annotation.

I just described my full issue in the following stackoverflow:

Stackover flow link

Please help me to fix this

I wouldn’t bother with lateinit if I was in your place. Just inject dependencies via constructor:

class CommentJob(private val userController: UserController) : Job {
	private val logger = LoggerFactory.getLogger(CommentJob::class.java)
	override fun execute(context: JobExecutionContext) {
		logger.debug("Inside Comment Job")
		logger.debug("End Comment Job")
1 Like

Thanks let me check this

@madmax1028 If I Inject via Constructor That also not working. its throws instantiationexception any idea

Can’t say for sure without more context. From what I see most likely something is trying to create an instance using no-arg constructor, which is no present here obliviously, but the thing is that Spring should normally use our constructor and inject dependencies even without @Autowired as long as it’s the only available construtor.

It’s almost like the Spring wasn’t used at all. It may somewhat explain why you also got the previous exception using lateinit. An instance was created without any concern for dependencies.

So Now how can I fix this? Stackoverflow and other internet medium d’not have more information about this issue.