0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Spring job memo

0
Last updated at Posted at 2023-08-16
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class CommandLineJobLauncher {

    public static void main(String[] args) {
        if (args.length < 1) {
            System.out.println("Usage: CommandLineJobLauncher <jobName>");
            return;
        }

        String jobName = args[0];

        ApplicationContext context = new ClassPathXmlApplicationContext("batch-config.xml");
        JobLauncher jobLauncher = context.getBean(JobLauncher.class);

        Job job = context.getBean(jobName, Job.class);
        if (job != null) {
            try {
                jobLauncher.run(job, new JobParametersBuilder().toJobParameters());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("Job not found: " + jobName);
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?