Spring boot 获取命令行参数作为@Scheduled spring boot的spring批处理作业参数
下面是我的spring boot主类,其中我有Spring boot 获取命令行参数作为@Scheduled spring boot的spring批处理作业参数,spring-boot,spring-batch,spring-scheduled,Spring Boot,Spring Batch,Spring Scheduled,下面是我的spring boot主类,其中我有@Scheduledbean @EnableScheduling @EnableBatchProcessing @SpringBootApplication(scanBasePackages = { "com.mypackage" }) public class MyMain { @Autowired private JobLauncher jobLauncher; @Autowired private Job j
@Scheduled
bean
@EnableScheduling
@EnableBatchProcessing
@SpringBootApplication(scanBasePackages = { "com.mypackage" })
public class MyMain {
@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job job;
public static void main(String[] args) throws Exception {
SpringApplication.run(MyMain.class, args);
}
@Scheduled(cron = "0 00 05 * * ?")
private void perform() throws Exception {
jobLauncher.run(job, new JobParameters());
}
}
我将从命令行接收参数,我需要将其作为作业参数。如何实现与
@Scheduled
相同的功能,带注释的方法不接受任何参数。您可以插入类型为ApplicationArguments
的bean,并使用它获取应用程序参数:
@EnableScheduling
@EnableBatchProcessing
@SpringBootApplication
public class MyMain {
@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job job;
@Autowired
private ApplicationArguments applicationArguments;
public static void main(String[] args) throws Exception {
SpringApplication.run(MyMain.class, args);
}
@Scheduled(cron = "0 00 05 * * ?")
private void perform() throws Exception {
String[] sourceArgs = applicationArguments.getSourceArgs();
JobParameters jobParameters; // create job parameters from sourceArgs
jobLauncher.run(job, jobParameters);
}
}
您可以在部分中找到有关应用程序参数
类型的更多详细信息
希望这有帮助。这应该如何工作?计划的方法在没有交互的情况下运行。您需要什么样的参数?