Spring boot 如何手动激发计划任务
我只想在不需要自动执行的情况下执行计划任务Spring boot 如何手动激发计划任务,spring-boot,scheduled-tasks,spring-batch,Spring Boot,Scheduled Tasks,Spring Batch,我只想在不需要自动执行的情况下执行计划任务 import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; i
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableScheduling
public class RunScheduler {
@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job job;
@RequestMapping("collector/test")
@Scheduled(fixedRate = 5000)
public void run() {
try {
String dateParam = new Date().toString();
JobParameters param = new JobParametersBuilder().addString("date", dateParam).toJobParameters();
System.out.println(dateParam);
JobExecution execution = jobLauncher.run(job, param);
System.out.println("Exit Status : " + execution.getStatus());
} catch (Exception e) {
e.printStackTrace();
}
}
我试过使用quartz,但我得到了许多由自动连线注释引起的错误,
如何从run方法中删除@Scheduled注释。此注释导致定期调用该方法
现在,当您想要手动执行计划任务时,请使用quartz scheduler API或其spring包装器,并完全控制何时调用任务。从run方法中删除@scheduled注释。此注释导致定期调用该方法
现在,当您想要手动执行计划任务时,请使用quartz scheduler API或其spring包装器,完全控制何时调用任务。错误是什么?请提供堆栈跟踪。您的意思是要手动启动(而不是执行)计划任务吗?i、 e.在调用收集器/测试之前,计划任务不应启动。一旦调用此端点,它应该每5秒运行一次。这是要求吗?问题是当我执行我的springboot应用程序时,计划任务开始自动运行我只想在调用收集器/测试时运行计划任务,错误是什么?请提供堆栈跟踪。您的意思是要手动启动(而不是执行)计划任务吗?i、 e.在调用收集器/测试之前,计划任务不应启动。一旦调用此端点,它应该每5秒运行一次。这是要求吗?问题是,当我执行springboot应用程序时,计划任务开始自动运行。我只想在调用收集器/测试时运行计划任务。这没有帮助。如果需要,他希望在保留当前计划的同时手动调用任务。这没有帮助。如果需要,他希望在保留当前计划的同时手动调用任务。