Spring XD Option Module – Batch Job with PostgreSQL Datasource

Spring XD Option Module is an approach to expose metadata of each module for configuration. The tutorial will guide you how to configure PostgreSQL Datasource with Spring XD Annotation: @ModuleOption.

Related articles:
Spring XD Stream – PostgreSQL JDBC Sink
Spring XD Batch Job – How to Start

I. Technology for Spring XD Option Module

– Java 8
– Spring XD 1.3.1.Release
– Spring Tool Suite – Version 3.8.1.RELEASE

II. Overview
1. Structure of Project

spring xd option module - structure

2. Step to do

– Create Simple Spring Maven project
– Customise pom.xml file for needed dependencies
– Create a simple model
– Create a Dao class
– Create a simple Tasklet
– Create a Application Configuration
– Define Batch job and config in /src/main/resources/config folder
– Start Spring XD Batch Job and Check Result

III. Practices
1. Create Simple Spring Maven project

Open Spring Tool Suite, on main menu, choose File->New->Spring Legacy Project, Choose Simple Projects, select Simple Spring Maven, Fill Project Name , then press Finish

2. Customise pom.xml file for needed dependencies

3. Create a simple model

Create a Customer java class

4. Create a Dao class

Create a simple JdbcDao

5. Create a simple Tasklet

Create a simple Tasklet for Spring XD Batch Job, use JDBC for insert data to Postgresql

6. Create a Application Configuration

Here we use Spring XD Option Module. Create a AppConfig.java file, use @ModuleOption for configuring JDBC Datasource

Create a config folder at src/main/resources, create a batchjob.properties file for locating the Java class configuration

7. Define Batch job

Define a simple Spring XD batch job with 1 step that using the CustomerTasklet.

8. Start Spring XD Batch Job and Check Result

Build project with Maven then start Spring XD with xd-singenode
Relate link Spring XD Batch Job – How to Start

Upload the batch job module with command:

At job module postgres-job, click on Create Definition label, We go to: Create Definition page, Input as below image:
spring xd option module - configuration step

Now launch the job, after COMPLETED status, go to DB and check result.
spring xd option module - configuration completed

Result:
spring xd option module - configuration completed - result

IV. Sourcecode

xdmoduleoptionconfigdatasource


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*