Kotlin Spring Boot Autoinired проблема латинита с классом кварцевого планировщика - PullRequest
0 голосов
/ 11 апреля 2020

Я просто реализую кварцевый планировщик с kotlin и пружинной загрузкой.

kotlin .UninitializedPropertyAccessException: свойство lateinit userController не было инициализировано

I знаю, что userController Объект не создается с помощью @autowired, в основном в kotlin lateinit создает объект ленивый, поэтому у меня нет идеи, чтобы решить эту проблему. Любой возможный способ создать объект в kotlin с нетерпением, чтобы решить эту проблему


Я получаю следующую ошибку:

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 

Код:


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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...