如何在 java spring boot 中启用日程表

问题描述 投票:0回答:1

我已经习惯了 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);
            } 
            
        }
}
java cron scheduled-tasks
1个回答
0
投票

SchedulerConfiguration这个类的包位置是什么?它应该在 RabbitMqPublishSubscribeApp 类的包名的子目录中。你能仔细检查一下吗?

© www.soinside.com 2019 - 2024. All rights reserved.