E
E
EVOSandru62019-07-01 00:18:16
Spring
EVOSandru6, 2019-07-01 00:18:16

How do I get the Spring scheduler up and running?

Hey guys. Tell me how to make the scheduler start and start working (Kotlin + Spring)?

@EnableScheduling
class ScheduledTasks {
    private val dateFormat = SimpleDateFormat("HH:mm:ss")

    @Scheduled(fixedRate = 5000)
    fun reportCurrentTime() {
        println("The time is now " + dateFormat.format(Date()))
    }
}

ServiceApplication :
@SpringBootApplication
@EnableWebFlux
class ServiceApplication

fun main(args: Array<String>) {
    runApplication<ServiceApplication>(*args)
}

I tried to transfer @EnableScheduling to ServiceApplication, but it didn't work(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Romanov, 2019-07-01
@EVOSandru6

Your ScheduledTasks is not a bean, judging by what I see. It is necessary to make it such, either by hanging an annotation on it @Component, or by declaring it @Beanas elsewhere

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question