Skip to content

dancortes-git/sbe-read-from-db-filtering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Spring Batch Examples - Read from DB with pagination and filtering

Project with examples using Spring Batch.

In this project there are configurations using JdbcPagingItemReader and ItemWriter simple implementation to write at log.

Requirements

You must set a database used for tests in our example we are using Postgresql. Below you can find a command line with docker.

docker run -d --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -v [local-directory-here]:/var/lib/postgresql/data postgres:10.10
  • Java 11
  • Maven 3.5.* or higher
  • Make sure your workspace is using encode UTF-8
  • The Lombok library is being used as a resource to help the creation of classes, check if your IDE has support/plugin to use Lombok. More information at https://projectlombok.org.

Initialize the Spring Batch database model

At application.properties file in the src / main / resources folder there is the parameter below that is commented by default, in the first time you run a spring batch with a empty database you need to create the data model of Spring Batch repository.

spring.batch.initialize-schema=always

Getting Started

Reference documentation

For further reference, please consider the following sections:

Guides

The guides below illustrate how to correctly use some spring batch features:

Environment variables

The application.properties file in the src / main / resources folder contains the environment variables that will be used by the application. If no environment variable is informed, the deafult values ​​will be used. Description of the variables:

  • REPOSITORY_DRIVER: (spring.datasource.driverClassName) Driver used to connect to the Spring Batch repository database. The default value is: org.h2.Driver, referring to database h2 in memory.
  • REPOSITORY_URL: (spring.datasource.url) Connection sring to the Spring Batch repository database. The default value is: jdbc:h2:mem:springbatch.
  • REPOSITORY_USER: (spring.datasource.username) User connecting to the Spring Batch repository database. The default value is: sa.
  • REPOSITORY_PASS: (spring.datasource.password) Password for connecting to the Spring Batch repository database. The default value is: .

Running the project with docker

The maven Jib plugin builds a Docker image. To create an image, execute the command below replacing the variable {imageName} with the name of the image to be generated. Jib will use the local Docker daemon:

mvn clean package jib:dockerBuild -Dimage={imageName}

To run the job using docker, run the command below:

docker run -it -e {environment variable}={environment variable value} {imageName} {job parameter}={job parameter value}

About

Spring Batch Example Project - Read from db filtering

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published