🌐
GitHub
github.com › chrisgleissner › spring-batch-rest
GitHub - chrisgleissner/spring-batch-rest: REST API for Spring Batch using Spring Boot 2.2 · GitHub
The spring-batch-rest-api dependency comes with jobs and jobExecutions REST endpoints. It is recommended if you don't require Quartz for scheduling your jobs. Maven: <dependency> <groupId>com.github.chrisgleissner</groupId> <artifactId>spri...
Starred by 91 users
Forked by 44 users
Languages   Java 99.9% | Procfile 0.1%
🌐
Maven Repository
mvnrepository.com › artifact › com.github.chrisgleissner › spring-batch-rest-api
Maven Repository: com.github.chrisgleissner » spring-batch-rest-api
aar amazon android apache api arm assets build build-system bundle client clojure cloud config cran data database eclipse example extension framework github gradle groovy io ios javascript jvm kotlin library maven mobile module npm osgi plugin resources rlang sdk server service spring sql starter ...
🌐
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
This lib isn't yet publish on Maven Central (coming soon). In the meantime, it is possible to use it through Jitpack. ... <repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.github.nicoraynaud</groupId> <artifactId>spring-batch-rest-api</artifactId> <version>v0.1.0</version> </dependency> </dependencies>
Starred by 6 users
Forked by 15 users
Languages   Java 99.7% | Shell 0.3%
🌐
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 - You can get the required dependencies with Maven or Gradle · You can create a custom ItemReader · During this blog post you will implement an ItemReader which reads the input data of your Spring Batch job from a REST API endpoint that processes GET requests send to the path: '/api/student/'. This API endpoint returns the information of all students who are enrolled to an online course.
🌐
Javainuse
javainuse.com › spring › springbootbatchtaskscheduler
Spring Boot Batch Job + Scheduler Simple Example
In a previous post we had implemented a Spring Boot Hello World Application. In that the Batch Job got triggered by a REST API call. 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 ...
🌐
Maven Central
repo1.maven.org › maven2 › com › github › chrisgleissner › spring-batch-rest-api › 1.4.0
Central Repository: com/github/chrisgleissner/spring-batch-rest-api/1.4.0
../ spring-batch-rest-api-1.4.0-javadoc.jar 2020-03-08 22:31 498905 spring-batch-rest-api-1.4.0-javadoc.jar.asc 2020-03-08 22:31 488 spring-batch-rest-api-1.4.0-javadoc.jar.md5 2020-03-08 22:31 32 spring-batch-rest-api-1.4.0-javadoc.jar.sha1 2020-03-08 22:31 40 spring-batch-rest-api-1.4.0-sources.jar 2020-03-08 22:31 15837 spring-batch-rest-api-1.4.0-sources.jar.asc 2020-03-08 22:31 488 spring-batch-rest-api-1.4.0-sources.jar.md5 2020-03-08 22:31 32 spring-batch-rest-api-1.4.0-sources.jar.sha1 2020-03-08 22:31 40 spring-batch-rest-api-1.4.0.jar 2020-03-08 22:31 35880 spring-batch-rest-api-1.4.
🌐
Baeldung
baeldung.com › home › spring › spring boot › spring boot with spring batch
Spring Boot With Spring Batch | Baeldung
January 8, 2024 - Building a REST API with Spring 5? Download the E-book · eBook – Maven – NPI EA (cat= Maven) Get Started with Apache Maven Download the E-book · eBook- Spring Reactive Guide – NPI EA (cat=Reactive) Spring Reactive Guide >> Join Pro and get the eBook ·
🌐
Maven Repository
mvnrepository.com › artifact › org.springframework.batch
Maven Repository: org.springframework.batch
Domain objects as well as serialization utilities used by Spring Batch Admin's REST endpoints. ... A sample web application (WAR project) for Spring Batch Admin console. ... aar android apache api arm assets build build-system bundle client clojure cloud config cran data database eclipse example extension framework github gradle groovy io ios javascript jvm kotlin library logging maven mobile module npm osgi persistence plugin resources rlang sdk server service spring sql starter testing tools ui web webapp
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);
    }
    
}
Find elsewhere
🌐
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 - We’ll implement a bulk API that takes the bulk requests and processes based on the bulkActionType enum and then returns the bulk status and customer data together. First, we’ll create an EnumMap in the BulkController class and map the ...
🌐
Baeldung
baeldung.com › home › spring › introduction to spring batch
Introduction to Spring Batch | Baeldung
December 24, 2024 - Get Started with Apache Maven: Download the E-book · eBook – Persistence – NPI EA (cat=Persistence) Working on getting your persistence layer right with Spring? Explore the eBook · eBook – RwS – NPI EA (cat=Spring MVC) Building a REST API with Spring?
🌐
Medium
prateek-ashtikar512.medium.com › spring-batch-read-from-rest-api-990d03208c1
Spring Batch — read from REST API - Prateek
September 4, 2023 - In this example, we’ll see how to make the call to REST API and feed that information into the reader. Student.java · import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @AllArgsConstructor @NoArgsConstructor @Data @Builder public class Student { private String emailAddress; private String name; private String purchasedPackage; } SpringBatchJob.java · import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.spri
🌐
GitHub
github.com › officiallysingh › spring-boot-batch-web
GitHub - officiallysingh/spring-boot-batch-web: Spring batch job as Spring Rest service
Access Statement APIs at http://localhost:8080/swagger-ui/index.html?urls.primaryName=Statement ... The application uses spring-batch-commons to avail common Spring Batch components, out of box. Maven
Author   officiallysingh
🌐
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 - 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 users of the API to follow the job progress.
🌐
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 - This is because each step is executed in its own separate transaction and can be separately committed, canceled or retried on failure. As for the item reader, processor, and writer, these are convenience implementations of Spring Batch for batch ...
🌐
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.
Top answer
1 of 2
2

It is possible to create your own custom ItemWriter.

In your case, please add the spring-boot-starter-web dependency to either your pom.xml or build.gradle

Example:

package com.example.batch;

import lombok.extern.log4j.Log4j2;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Log4j2
public class RestItemWriter implements ItemWriter<String> {
    @Autowired
    RestTemplate restTemplate;

    public RestItemWriter(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @Override
    public void write(List<? extends String> items) throws Exception {
        ResponseEntity<Users> users = restTemplate.getForEntity("https://jsonplaceholder.typicode.com/users/1", Users.class);

        log.info("Status code is: " + users.getStatusCode());
    }
}


package com.example.batch;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Users {

    public String id;
    public String name;
    public String username;
    public String email;
    public String phone;
}

More information about custom item writers here

2 of 2
1

Of course! you can send the processed records to another system using REST call in ItemWriter.

Use the below code in your RestItemWriter class.

private RestTemplate restTemplate;

@Override
public void write(@NonNull Chunk<? extends Payload> chunk) throws Exception {

    for((Payload payload : chunk){

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", "xx-tokenString-xx");
                    
        HttpEntity<Payload> requestEntity = new HttpEntity<>(payload, headers);

        try{
            ResponseEntity<Object> response = restTemplate.exchange(url, HttpMethod.PATCH, requestEntity, Object.class);
            LOGGER.info("Request hits the server {}", response.getBody());
        } catch(HttpClientErrorException e){
            LOGGER.error("HttpClientErrorException occured during connection {}", e.getMessage());
        } catch (Exception e) {
            LOGGER.error("Exception occured during connection {}", e.getMessage());
        }

    }
}

To make HTTP Patch request using RestTemplate, below configurations are mandatory, for other HTTP calls you may ignore it.

 @Bean
    public RestTemplate restTemplate() {
        LOGGER.info("restTemplate Bean has bean created");
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
        RestTemplate restTemplate = new RestTemplate(factory);
        return restTemplate;
    }

You have to add the below dependency in pom.xml to use CloseableHttpClient, and HttpClients.

<dependency>
    <groupId>org.apache.httpcomponents.client5</groupId>
    <artifactId>httpclient5</artifactId>
</dependency>
🌐
Bjoernkw
bjoernkw.com › home › software › enterprise software › spring batch resources: batch processing, etl and data conversion
Spring Batch Resources: Batch Processing, ETL And Data Conversion | Björn Wilmsmann
October 18, 2021 - If you need to read Microsoft Excel files with Spring Batch the spring-batch-excel extension might come in handy: mdeinum/spring-batch-extensions · There’s also plenty of expedient information available on Stack Overflow that can help you with solving not-so-common problems such as how to read from a REST API or writing to a SOAP WebService with Spring Batch:
🌐
BlackSlate
blackslate.io › articles › data-dump-using-spring-batch
Data dumping through REST API using Spring Batch
Most of the cloud services provide API to fetch their data. But data will be given as paginated results as returning the complete data will overshoot the response payload. To discover the complete list of books or e-courses or cloud machine ...