You have to build job with JobbuilderFactory:

    @Configuration
@EnableBatchProcessing
public class BatchConfiguration {

    @Autowired
    public JobBuilderFactory jobBuilderFactory;

    @Autowired
    public StepBuilderFactory stepBuilderFactory;

    @Bean
    public SomeReader<Some> reader() {

        // some reader configuration
        return reader;
    }

    @Bean
    public SomeProcessor processor() {
        return new SomeProcessor();
    }

    @Bean
    public SomeWriter<Person> writer() {
        // some config
        return writer;
    }

    @Bean
    public Job someJob() {
        return jobBuilderFactory.get("someJob")
                .flow(step1())
                .end()
                .build();
    }

    @Bean
    public Step step1() {
        return stepBuilderFactory.get("step1")
                .<Some, Some> chunk(10)
                .reader(reader())
                .processor(processor())
                .writer(writer())
                .build();
    }
    }

Start job in rest controller:

@RestController
@AllArgsConstructor
@Slf4j
public class BatchStartController {

    JobLauncher jobLauncher;

    Job job;

    @GetMapping("/job")
    public void startJob() {
    //some parameters
        Map<String, JobParameter> parameters = new HashMap<>();
        JobExecution jobExecution = jobLauncher.run(job, new JobParameters(parameters));
        }    }

And one important detail - add in application.properties:

spring.batch.job.enabled=false

to prevent job self start.

Answer from Valeriy K. on Stack Overflow
🌐
Baeldung
baeldung.com › home › spring › spring web › implement bulk and batch api in spring
Implement Bulk and Batch API in Spring | Baeldung
July 17, 2024 - A batch API is a bundle of various actions on resources in a single call. These resource operations may not have any coherence. Potentially, each request route can be independent of another. In short, the “batch” term means batching different requests. We don’t have many well-defined standards or specifications to implement the bulk or batch operations. Also, many popular frameworks like Spring ...
🌐
Spring
docs.spring.io › spring-batch › docs › current › api › index.html
Overview (Spring Batch 5.2.5 API)
APIs for the configuration of Spring Integration components through XML. ... Message based job launching components. ... Remote partitioning components. ... Infrastructure interfaces and primary dependencies for item concerns. ... Adapters for Plain Old Java Objects. ... AMQP related batch components.
🌐
Spring
docs.spring.io › spring-batch › docs › current › api
Overview (Spring Batch 5.2.6 API)
APIs for the configuration of Spring Integration components through XML. ... Message based job launching components. ... Remote partitioning components. ... Infrastructure interfaces and primary dependencies for item concerns. ... Adapters for Plain Old Java Objects. ... AMQP related batch components.
Top answer
1 of 2
2

You have to build job with JobbuilderFactory:

    @Configuration
@EnableBatchProcessing
public class BatchConfiguration {

    @Autowired
    public JobBuilderFactory jobBuilderFactory;

    @Autowired
    public StepBuilderFactory stepBuilderFactory;

    @Bean
    public SomeReader<Some> reader() {

        // some reader configuration
        return reader;
    }

    @Bean
    public SomeProcessor processor() {
        return new SomeProcessor();
    }

    @Bean
    public SomeWriter<Person> writer() {
        // some config
        return writer;
    }

    @Bean
    public Job someJob() {
        return jobBuilderFactory.get("someJob")
                .flow(step1())
                .end()
                .build();
    }

    @Bean
    public Step step1() {
        return stepBuilderFactory.get("step1")
                .<Some, Some> chunk(10)
                .reader(reader())
                .processor(processor())
                .writer(writer())
                .build();
    }
    }

Start job in rest controller:

@RestController
@AllArgsConstructor
@Slf4j
public class BatchStartController {

    JobLauncher jobLauncher;

    Job job;

    @GetMapping("/job")
    public void startJob() {
    //some parameters
        Map<String, JobParameter> parameters = new HashMap<>();
        JobExecution jobExecution = jobLauncher.run(job, new JobParameters(parameters));
        }    }

And one important detail - add in application.properties:

spring.batch.job.enabled=false

to prevent job self start.

2 of 2
0

Solved by myself, as suggested here: Spring Boot: Cannot access REST Controller on localhost (404)

@SpringBootApplication
@EnableBatchProcessing
@EnableScheduling
@ComponentScan(basePackageClasses = JobStatusApi.class)
public class UpdateInfoBatchApplication {
    
    public static void main(String[] args) {
        SpringApplication.run(UpdateInfoBatchApplication.class, args);
    }
    
}
🌐
Petri Kainulainen
petrikainulainen.net › home › blog › spring batch tutorial: reading information from a rest api
Spring Batch Tutorial: Reading Information From a REST API - Petri Kainulainen
December 21, 2020 - Spring Batch doesn’t have an ItemReader that can read information from a REST API. If you want to read the input data of your batch job from a REST API, you can read this information by using the RestTemplate class. The next part of this tutorial describes how you can read the input data of your batch job from an Excel spreadsheet. P.S. You can get the example application of this blog post from Github.
🌐
GitHub
github.com › chrisgleissner › spring-batch-rest
GitHub - chrisgleissner/spring-batch-rest: REST API for Spring Batch using Spring Boot 2.2 · GitHub
REST API for Spring Batch based on Spring Boot 2.2 and Spring HATOEAS.
Starred by 91 users
Forked by 44 users
Languages   Java 99.9% | Procfile 0.1%
🌐
Medium
medium.com › @andrejtaneski › using-spring-batch-in-a-rest-api-application-493b812d80d1
Using Spring Batch in a REST API Application | by Andrej Taneski | Medium
March 24, 2023 - In this post we’ll take a look at the case where a user interaction is required in order to start off a batch processing job and we’ll enable users to do so through a REST API. This post is meant to be a basic guide on using Spring Batch in your projects, but as with any technology, the official documentation can take you much further.
🌐
Medium
prateek-ashtikar512.medium.com › spring-batch-read-from-rest-api-990d03208c1
Spring Batch — read from REST API - Prateek
September 4, 2023 - @SpringBootApplication @EnableBatchProcessing @EnableScheduling public class SpringBatchExampleApplication implements CommandLineRunner { @Autowired private Job job; @Autowired private JobLauncher jobLauncher; @Bean RestTemplate restTemplate() { return new RestTemplate(); } public static void main(String[] args) { SpringApplication.run(SpringBatchExampleApplication.class, args); } @Override public void run(String... args) throws Exception { jobLauncher.run(job, newExecution()); } private JobParameters newExecution() { Map<String, JobParameter> parameters = new HashMap<>(); JobParameter paramet
Find elsewhere
🌐
Spring
docs.spring.io › spring-batch › docs › 4.2.x › api › index.html
KafkaItemReader (Spring Batch 4.2.8.RELEASE API)
JavaScript is disabled on your browser · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version
🌐
GitHub
github.com › nicoraynaud › spring-batch-rest-api
GitHub - nicoraynaud/spring-batch-rest-api: Spring Boot library that exposes a REST API to manage Spring batch (start, stop, list, search jobs, job executions and history) · GitHub
swagger: '2.0' info: description: Spring Batch REST API endpoints documentation version: 0.1.0 title: Spring Batch REST API contact: {} license: {} host: localhost:8080 basePath: "/" tags: - name: jobs-resource description: Jobs Resource paths: "/management/jobs": get: tags: - jobs-resource summary: getJobs operationId: getJobsUsingGET produces: - "*/*" parameters: - name: jobName in: query description: jobName required: false type: string responses: '200': description: OK schema: type: array items: "$ref": "#/definitions/JobDescriptionDTO" '401': description: Unauthorized '403': description:
Starred by 6 users
Forked by 15 users
Languages   Java 99.7% | Shell 0.3%
🌐
Spring
spring.io › guides › gs › batch-processing
Getting Started | Creating a Batch Service
The job ends, and the Java API produces a perfectly configured job. In the step definition, you define how much data to write at a time. In this case, it writes up to three records at a time. Next, you configure the reader, processor, and writer by using the beans injected earlier. The last bit of batch configuration is a way to get notified when the job completes. The following example (from src/main/java/com/example/batchprocessing/JobCompletionNotificationListener.java) shows such a class:
🌐
Baeldung
baeldung.com › home › spring › introduction to spring batch
Introduction to Spring Batch | Baeldung
December 24, 2024 - A quick guide to using Spring Batch for a simple but practical scenario - moving some data from CSV to XML.
🌐
Javainuse
javainuse.com › spring › springbootbatchtaskscheduler
Spring Boot Batch Job + Scheduler Simple Example
In this post we develop a simple Spring Boot Batch application where batch job gets triggered using a scheduler. Consider the simple use case where the user wants to delete files from a particular location everyday at a particular time. We will schedule this batch job using the scheduler.
🌐
Keitaro
keitaro.com › insights › 2023 › 03 › 23 › using-spring-batch-in-a-rest-api-application
Using Spring Batch in a REST API Application – Keitaro
March 23, 2023 - Spring Batch offers so much more than the example described in this post, so be sure to refer to the official documentation. Here we looked at an example of how to define job steps, jobs, and how to run jobs asynchronously from a REST controller. What you might want to do next is provide means for the API ...
🌐
DZone
dzone.com › data engineering › data › spring batch: processing data from web service to mongodb
Spring Batch: Processing Data From Web Service to MongoDB
December 12, 2018 - Batch reader implement @LineMapper. You can adapt the reader to our data sources (Example): import java.util.List; import org.springframework.batch.item.file.LineMapper; import com.ahajri.batch.beans.BCountry; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.CollectionType; public class BCountryJsonLineMapper implements LineMapper<List<BCountry>> { private final ObjectMapper mapper = new ObjectMapper(); @Override public List<BCountry> mapLine(String line, int lineNumber) throws Exception { CollectionType collectionType =mapper.getTypeFactory().constructCollectionType(List.class, BCountry.class); return mapper.readValue(line, collectionType); } }
🌐
Spring
spring.io › projects › spring-batch
Spring Batch
Simple as well as complex, high-volume batch jobs can leverage the framework in a highly scalable manner to process significant volumes of information.
🌐
Gitbooks
paramothers.gitbooks.io › mybook › content › mydocs › JavaTechnologies › spring › springbatch.html
Spring Batch API · Traveled By Java - paramothers
General API-SpringBatch 3.0 API- Job Repository API-Repeat API-Retry API-Step API- Job API-JunitTesst API-Listener API-policy & status API-ItemProcessor API-ItemReader API-ItemWriter Spring batch LLR SpringBatch-SESSION
🌐
Javainuse
javainuse.com › spring › bootbatch
Spring Boot Batch Tutorial- Hello World example
Spring Batch - Table Of Contents Spring Batch Hello World example-Write data from csv to xml file Spring Boot Batch Simple example Spring Batch - Difference between Step, Chunk and Tasklet Spring Batch Tasklet - Hello World example Spring Boot + Batch + Task Scheduler Example
🌐
Spring
docs.spring.io › spring-batch › docs › 4.3.x › api › index.html
RepositoryItemReader (Spring Batch 4.3.10 API)
March 4, 2010 - JavaScript is disabled on your browser · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version
🌐
DZone
dzone.com › software design and architecture › integration › spring boot/batch tutorial: integration with hbase rest api and data ingestion
Spring Boot/Batch Tutorial: Integration With HBASE REST API and Data Ingestion
April 5, 2019 - A developer gives a quick tutorial on how to work with Java to integrate the Spring Boot/Spring Batch frameworks in an app and ingest data from a RESTful API