@Scheduled 任务执行失败

@Scheduled tasks failing to execute

我在 Windows 上安装了 grails 4.0.2 运行 7. 按照此处找到的@Scheduled 指南的最基本部分:

https://guides.grails.org/grails-scheduled/guide/index.html

我没有收到控制台的任何输出。我什至尝试使用他们提供的项目。相关代码如下:

在grails-app/conf/logback.groovy

logger('demo', INFO, ['STDOUT'], false)

在grails-app/services/demo/HelloWorldJobService.groovy

package demo

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.scheduling.annotation.Scheduled

import java.text.SimpleDateFormat

@Slf4j 
@CompileStatic 
class HelloWorldJobService {

    static lazyInit = false 

    @Scheduled(fixedDelay = 10000L) 
    void executeEveryTen() {
        log.info "Simple Job every 10 seconds :{}", new SimpleDateFormat("dd/M/yyyy hh:mm:ss").format(new Date())
    }

    @Scheduled(fixedDelay = 45000L, initialDelay = 5000L) 
    void executeEveryFourtyFive() {
        log.info "Simple Job every 45 seconds :{}", new SimpleDateFormat("dd/M/yyyy hh:mm:ss").format(new Date())
    }
}

由于这是一个简单的指南,我假设我这边有配置错误,但我还没有找到它。

我认为该指南不正确 - spring-如果没有 @EnableScheduling 应用程序或配置的调度程序,调度将无法工作 -

https://spring.io/guides/gs/scheduling-tasks/#_enable_scheduling

谢谢大家。我固定了指南。 eric 指出的问题。

此外,我发现我们的文档中隐藏了这个。谢谢

https://docs.grails.org/latest/guide/upgrading.html

预定方法

In Grails 3 no configuration or additional changes were necessary to use the Spring @Scheduled annotation. In Grails 4 you must apply the @EnableScheduling annotation to your application class in order for scheduling to work.