How to start with Spring Batch using Spring Boot – Java Config

preview_player
Показать описание
How to start with Spring Batch using Spring Boot – Java Config
Many business operations need to process with batch job for critical environment. Spring Batch is a lightweight framework to boot the batch application.

The tutorial will guide you how to start with Spring Batch using Spring Boot.

I. Technologies for Spring Batch tutorial

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.4.0.RELEASE

II. Overview

1. Structure of project

2. Step to do

– Create Spring Boot project
– Add needed dependencies
– Configure datasource for Batch Job Repository
– Create Step:Reader, Processor, Writer
– Configure Batch Job
– Create a Controller for launch Job
– Run & Check result

3. Demo Video

III. Practices

1. Create Spring Boot project
2. Add needed dependencies
– Add dependencies: Web MVC, Spring Batch, PostgreSQL

3. Config datasource for Batch Job repository
4. Create Step:Reader, Processor, Writer
public interface ItemReader: Strategy interface for providing the data.
Implementations are expected to be stateful and will be called multiple times for each batch, with each call to read() returning a different value and finally returning null when all input data is exhausted.
Implementations need not be thread-safe and clients of a ItemReader need to be aware that this is the case.
A richer interface (e.g. with a look ahead or peek) is not feasible because we need to support transactions in an asynchronous batch.

public interface ItemProcessor: Interface for item transformation. Given an item as input, this interface provides an extension point which allows for the application of business logic in an item oriented processing scenario. It should be noted that while it’s possible to return a different type than the one provided, it’s not strictly necessary. Furthermore, returning null indicates that the item should not be continued to be processed.

public interface ItemWriter: Basic interface for generic output operations. Class implementing this interface will be responsible for serializing objects as necessary. Generally, it is responsibility of implementing class to decide which technology to use for mapping and how it should be configured.

5. Enable Spring Batch

In main class, use @EnableBatchProcessing: Enable Spring Batch features and provide a base configuration for setting up batch jobs in an @Configuration class.

6. Configure Batch Job

Create a configuration file and enable Spring batch via annotations:

– @Configuration

7. Create a Controller for launch Job

Create a simple controller JobLauncherController with 1 @RequestMapping(“/launchjob”)

8. Run & Check result

– Maven build:clean install
– Run project with mode: Spring Boot App

IV. Source code
SpringBatch
Рекомендации по теме
Комментарии
Автор

There is an inbuilt file in spring
SimpleJoblauncher.java which is giving output
No TaskExecutor has been set, defaulting to synchronous executor.

Pls. help to resolve the same.

taruchitgoyal
welcome to shbcf.ru