Issue
Given you have this job configuration below, how can you execute the job scrubWord
in command line in a Spring Boot - Spring Batch application using Maven command?
@Configuration
public class WordConfiguration {
@Autowired
WordReader wordReader;
@Autowired
WordProcessor wordProcessor;
@Autowired
WordWriter wordWriter;
@Bean
public Job scrubWords() {
Step scrubWords = stepBuilders
.get("scrubWord")
.<Set<String>, Set<String>>chunk(1)
.reader(wordReader)
.processor(wordProcessor)
.writer(wordWriter)
.build();
return jobBuilders.get("wordScrubber")
.start(scrubWords)
.build();
}
}
Solution
Solution 1: Inside file application.properties
add
spring.batch.job.names=wordScrubber
If you have many jobs
spring.batch.job.names=wordScrubber,foo,bar
then run
mvn spring-boot:run
Solution 2: Best practice way is
$ java -jar myapp.jar --server.port=7070 someParameter=someValue
Not use Maven parameter, use parameter when run JAR file. See reference document at https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.batch.running-from-the-command-line
Answered By - Do Nhu Vy
Answer Checked By - David Goodson (JavaFixing Volunteer)