Class SpringBootBatchCommandLine


  • public class SpringBootBatchCommandLine
    extends Object
    Launcher for launching batch jobs from the command line when Spring Boot is used. Similar to the CommandLineJobRunner, which does not work very well with Spring Boot.

    Do not use this class if Spring Boot is not used!

    It expects the full class name of the Spring Boot configuration class to be used as first argument, the class/XML file for configuring the job as second argument and the job name as third.
    Moreover parameters can be specified as further arguments (convention: key1=value1 key2=value2 ...).

    Example:
    java com.devonfw.module.batch.common.base.SpringBootBatchCommandLine com.devonfw.gastronomy.restaurant.SpringBootBatchApp classpath:config/app/batch/beans-productimport.xml productImportJob drinks.file=file:import/drinks.csv date(date)=2015/12/20

    For stopping all running executions of a job, use the -stop option.

    Example:
    java com.devonfw.module.batch.common.base.SpringBootBatchCommandLine com.devonfw.gastronomy.restaurant.SpringBootBatchApp classpath:config/app/batch/beans-productimport.xml productImportJob -stop

    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • launcher

        private org.springframework.batch.core.launch.JobLauncher launcher
      • locator

        private org.springframework.batch.core.configuration.JobLocator locator
      • parametersConverter

        private org.springframework.batch.core.converter.JobParametersConverter parametersConverter
      • operator

        private org.springframework.batch.core.launch.JobOperator operator
    • Constructor Detail

      • SpringBootBatchCommandLine

        public SpringBootBatchCommandLine()
    • Method Detail

      • main

        public static void main​(String[] args)
                         throws Exception
        Parameters:
        args - the command-line arguments.
        Throws:
        Exception - in case of an error.
      • handleIncorrectParameters

        private static void handleIncorrectParameters()
      • getReturnCode

        protected int getReturnCode​(org.springframework.batch.core.JobExecution jobExecution)
        Parameters:
        jobExecution - the JobExecution.
        Returns:
        the corresponding exit code.
      • findBeans

        private void findBeans​(org.springframework.context.ConfigurableApplicationContext ctx)
      • execute

        public void execute​(SpringBootBatchCommandLine.Operation operation,
                            List<String> configurations,
                            String jobName,
                            List<String> parameters)
                     throws Exception
        Initialize the application context and execute the operation.

        The application context is closed after the operation has finished.

        Parameters:
        operation - The operation to start.
        configurations - The sources of bean configurations (either JavaConfig classes or XML files).
        jobName - The name of the job to launch/stop.
        parameters - The parameters (key=value).
        Throws:
        Exception - in case of an error.
      • startBatch

        private void startBatch​(org.springframework.context.ConfigurableApplicationContext ctx,
                                String jobName,
                                List<String> parameters)
                         throws Exception
        Throws:
        Exception
      • stopBatch

        private void stopBatch​(org.springframework.context.ConfigurableApplicationContext ctx,
                               String jobName)
                        throws Exception
        Throws:
        Exception