Class SpringBootBatchCommandLine
- java.lang.Object
-
- com.devonfw.module.batch.common.base.SpringBootBatchCommandLine
-
public class SpringBootBatchCommandLine extends Object
Launcher for launching batch jobs from the command line when Spring Boot is used. Similar to theCommandLineJobRunner, 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/20For 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSpringBootBatchCommandLine.OperationAvailable operations
-
Field Summary
Fields Modifier and Type Field Description private org.springframework.batch.core.launch.JobLauncherlauncherprivate org.springframework.batch.core.configuration.JobLocatorlocatorprivate static org.slf4j.LoggerLOGprivate org.springframework.batch.core.launch.JobOperatoroperatorprivate org.springframework.batch.core.converter.JobParametersConverterparametersConverter
-
Constructor Summary
Constructors Constructor Description SpringBootBatchCommandLine()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexecute(SpringBootBatchCommandLine.Operation operation, List<String> configurations, String jobName, List<String> parameters)Initialize the application context and execute the operation.private voidfindBeans(org.springframework.context.ConfigurableApplicationContext ctx)protected intgetReturnCode(org.springframework.batch.core.JobExecution jobExecution)private static voidhandleIncorrectParameters()static voidmain(String[] args)private voidstartBatch(org.springframework.context.ConfigurableApplicationContext ctx, String jobName, List<String> parameters)private voidstopBatch(org.springframework.context.ConfigurableApplicationContext ctx, String jobName)
-
-
-
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
-
-
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- theJobExecution.- 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
-
-