I'm just implements quartz scheduler with kotlin and spring boot.
kotlin.UninitializedPropertyAccessException: lateinit property userController has not been initialized
I know userController Object is not created with @autowired basically in kotlin lateinit create object lazy so i d'not have idea to fix this issue. any possible way to create object in kotlin with eagerly to fix this issue
I'm Getting the following error:
Full Error Log : For reference
21:02:00.037 [DatabaseScheduler_Worker-1] ERROR org.quartz.core.JobRunShell - Job commentJobGroup.commentJob threw an unhandled Exception:
kotlin.UninitializedPropertyAccessException: lateinit property userController has not been initialized
at com.lovevirus.kotlinQuartzScheduler.scheduler.Jobs.CommentJob.getUserController(CommentJob.kt:17)
at com.lovevirus.kotlinQuartzScheduler.scheduler.Jobs.CommentJob.execute(CommentJob.kt:21)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
21:02:00.038 [DatabaseScheduler_Worker-1] ERROR org.quartz.core.ErrorLogger - Job (commentJobGroup.commentJob threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property userController has not been initialized
at com.lovevirus.kotlinQuartzScheduler.scheduler.Jobs.CommentJob.getUserController(CommentJob.kt:17)
at com.lovevirus.kotlinQuartzScheduler.scheduler.Jobs.CommentJob.execute(CommentJob.kt:21)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
... 1 common frames omitted
Code:
import org.quartz.Job
import org.quartz.JobExecutionContext
import org.springframework.stereotype.Component
import com.lovevirus.kotlinQuartzScheduler.controller.UserController;
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
@Component
class CommentJob : Job {
private val logger: Logger = LoggerFactory.getLogger(CommentJob::class.java)
@Autowired
lateinit var userController : UserController;
override fun execute(p0: JobExecutionContext?) {
logger.debug("Inside Comment Job");
userController.getUser();
logger.debug("End Comment Job");
}
}
Thanks in advance