HomeОбразованиеRelated VideosMore From: grokonez

How to use Spring Batch Restartable Function

3 ratings | 886 views
http://javasampleapproach.com/spring-framework/spring-batch/use-spring-batch-restartable-function#more-2511 How to use Spring Batch Restartable Function SpringBatch provides a restartable mechanics with a Job, in the How to use Spring Batch Restartable Function tutorial, JavaSampleApproach will present to you the principle of this function with SpringBoot. Related Post: 1. How to start with Spring Batch using Spring Boot – Java Config at: http://javasampleapproach.com/spring-framework/spring-boot/start-spring-batch-using-spring-boot 2. Spring Batch XML Config by Spring Boot at: http://javasampleapproach.com/spring-framework/spring-batch/spring-batch-xml-config-spring-boot 3. Spring Batch Job with Parallel Steps at: http://javasampleapproach.com/spring-framework/spring-batch/spring-batch-job-parallel-steps 4. How to import CSV data to PostgreSQL Database using Spring Batch Job at: http://javasampleapproach.com/spring-framework/how-to-import-csv-data-to-postgresql-database-using-spring-batch-job I. Technologies – Java 1.8 – Maven 3.3.9 – Spring Boot: 1.4.3.RELEASE – Spring Tool Suite – Version 3.8.1.RELEASE II. Overview Create a Batch Job which has a simple step with a Reader & Writer. Reader reads a list file-paths then pass them to a Writer. The Write uses file paths to process content of each file. With created JOB, test a restartable function base on FileNotFound Error. Note: a Batch Job is created with restartable default. Spring Batch also supports configuration to prevent the restartable function. 1. Project Structure 2. Step to do – Create SpringBoot project – Create simple step – Config a Batch Job – Create a Job Launch controller – Config Batch Job Database – Enable Batch Job – Scenario Test III. Spring Batch Restartable Practices 1. Create a SpringBoot project Open Spring Tool Suite, on main menu, choose File-New-Spring Starter Project, input project info. Press Next then Finish, a Spring Boot project will be created successfully. – Open pom.xml file, add Web MVC, PostgreSQL and Spring Batch dependencies 2. Create classes Reader & Writer for simple step - Create a Reader class - Create a Writer class 3. Config a Batch Job Config a Simple Batch Job 4. Create a Job Launch controller – Create a simple Controller for Job Launching. 5. Config Batch Job Database Config DataBase’s info for Spring Batch: spring.datasource.url=jdbc:postgresql://localhost/testdb spring.datasource.username=postgres spring.datasource.password=123 spring.batch.job.enabled=false 6. Enable Batch Job In main class of Spring Boot project, use @EnableBatchProcessing to enable Spring Batch. 7. Scenario Test – Build & Run the Spring Boot Batch Job. The Reader will forward a file name: C:\\readfile\\1.txt to Writer. Delete a file C:\\readfile\\1.txt, then makes a launch request: http://localhost:8080/launchjob A Job Instance is created with Empty Parameters: IV. Prevent Restartable SpringBatch also supports a config to prevent restartable ability of a Job even if a Job Instance’s Execution with FAIL status. How to configure? Just use a little code strong.preventRestart(), details with BatchConfig class V. Sourcecode SpringBatchRestartableFunction
Html code for embedding videos on your blog
Text Comments (0)

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.