@计划的任务无法执行

时间:2020-03-25 11:30:52

标签: windows grails scheduled-tasks

我有在Windows 7上运行的grails 4.0.2。遵循@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())
    }
}

由于这只是一个简单的指南,因此我假设最后会出现配置错误,但是我还没有找到它。

2 个答案:

答案 0 :(得分:1)

我认为指南不正确-如果没有在应用程序上配置@EnableScheduling或配置了计划程序,则无法进行春季计划-

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

答案 1 :(得分:0)

谢谢大家。我已经固定住了导游。 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.
相关问题