我已经习惯了 java Scheduled cron 在我的项目中设置自动作业。 我在主 SpringBootApplication 和作业类中添加配置,但没有任何反应,作业不会在我设置的每次(10 秒)时运行。 那么我该如何解决呢?
这是主要的开始。
@SpringBootApplication
@EnableScheduling
public class RabbitMqPublishSubscribeApp implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(RabbitMqPublishSubscribeApp.class, args);
}
}
这是我的工作
@Component
public class SchedulerConfiguration {
@Autowired
private RabbitMqJobs jobs;
@Scheduled(cron = "*/10 * * * * *")
public void schedulePutQueue() {
try {
System.out.println("BEGIN JOB SIGN");
jobs.putDataToQueue();
} catch(Exception e) {
ReportLogger.logger.error("Exception main:" +e.getStackTrace().toString(),e);
}catch (Error er) {
ReportLogger.logger.error("Error main:" +er.getStackTrace().toString(),er);
}
}
}
SchedulerConfiguration这个类的包位置是什么?它应该在 RabbitMqPublishSubscribeApp 类的包名的子目录中。你能仔细检查一下吗?