java 定时任务cron不起作用失效

0.查看是否引入对应的pom

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

1.项目启动类是否添加@EnableScheduling注解

2.在业务类中查看是否添加@Service @Component等注入Spring的注解

3.方法上是否添加@Scheduled注解

请看注释

//1.@Scheduled(cron = "${TestServiceImpl.cron}") 的""内需要加${}才能导入yml的配置 
//2.方法不能有参数和返回值。
@Scheduled(cron = "${TestServiceImpl.cron}")
public void test(){
//todo
}

4.检查cron表达式 是否正确 。

4.1 如格式正确,且满足以上条件,建议用 0/30 * * * * ? 此表达式测试

因为很容易搞错 如:
0/30 * * * * ?和 0/30 0 0 * * ?
0/30 * * * * ? 是每30秒执行一次
0/30 0 0 * * ? 是0点的时候 30秒执行一次
所以可能是你的表达式还没到达执行时间.