springboot开启定时任务不起作用
1、主启动类开启@EnableScheduling 并且 该配置所在的package要能被扫描到
package com.gccloud.dataroom.core.config; import com.gccloud.dataroom.core.module.receive.service.IDataReceiveService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.stereotype.Service; import lombok.extern.slf4j.Slf4j; @Slf4j @EnableScheduling @Service public class Sched { @Autowired private IDataReceiveService dataReceiveService; @Bean public TaskScheduler poolScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setThreadNamePrefix("poolScheduler"); scheduler.setPoolSize(10); return scheduler; } // @Async(value = "asyncPoolTaskExecutor") @Scheduled(cron = "*/5 * * * * ?") public void clearRealtimeCacheData() { log.info("每5秒执行一次"); } }