如果您不想使用CommandLineRunner(出于某种原因或者如果您需要一些自定义逻辑),请使用Spring Boot应用程序,您可以随时执行以下操作:
public static void main(String[] args) {
SpringApplication app = new SpringApplication(YourApplication.class);
app.setWebEnvironment(false);
ConfigurableApplicationContext ctx = app.run(args);
JobLauncher jobLauncher = ctx.getBean(JobLauncher.class);
Job job = ctx.getBean("your-job-here", Job.class);
JobParameters jobParameters = new JobParametersBuilder().toJobParameters();
JobExecution jobExecution = jobLauncher.run(job, jobParameters);
BatchStatus batchStatus = jobExecution.getStatus();
}