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秒执行一次"); } }
标签:springboot,不起作用,springframework,scheduler,org,scheduling,import,定时,annotation From: https://www.cnblogs.com/xuchao0506/p/17890727.html