Spring Batch – Read once, Write multi example

Sometimes, we need to read once, write multi ETL with Spring Batch. Spring Batch supports it with CompositeItemWriter (org.springframework.batch.item.support.CompositeItemWriter). Sample table schema Declaration of CompositeItemWriter Make sure that CompositeItemWriter has 2 delegates (TestWriter1, TestWriter2). You can use any Writer as it's delegate. Full Job declaration Make sure that Job task is using new CompositeItemWriter instead … Continue reading Spring Batch – Read once, Write multi example

More on Spring Batch Writer

Spring Batch Writer is the implementation of org.springframework.batch.item.ItemWriter. You can write a custom writer, but Spring Batch already has some useful implementations, such as org.springframework.batch.item.amqp.AmqpItemWriter for AMQP brokers such as RabbitMQ org.springframework.batch.item.file.FlatFileItemWriter for a file org.springframework.batch.item.database.JpaItemWriter for database using JPA org.springframework.batch.item.database.JdbcBatchItemWriter for writing to database with plain SQL This post shows detailed information on using … Continue reading More on Spring Batch Writer

More on Spring Batch Reader

Spring Batch Job is composed of Reader, Processor and Writer. This post shows some more details on Reader. Reader is the implementation of org.springframework.batch.item.Reader. I recommend to use the following implementations. AmqpItemReader (org.springframework.batch.item.amqp.AmqpItemReader) : to interact with queue such as RabbitMQ FlatFileItemReader (org.springframework.batch.item.file.FlatFileItemReader) : to interact with a file JdbcCursorItemReader (org.springframework.batch.item.database.JdbcCursorItemReader) : to interact with … Continue reading More on Spring Batch Reader

Combining multiple transactional method in one transaction

Method with @Transactional commits the transaction when it returns. If you want to combine multiple transactional method in one transaction, propagation policy is the solution. Solution A To make a parent method with @Transactional To delete @Transactional at sub methods to combine the transaction Solution B To make a parent method with @Transactional (default propagation … Continue reading Combining multiple transactional method in one transaction

Spring Transaction with @Transactional explained

The most easy way to Spring Transaction is to use @Transactional. The following is basic step to use it. Required spring component spring-context.jar, spring-tx.jar, spring-jdbc.jar and additional dependencies Spring context <tx:annotation-driven> must be declared to enable @Transactional TransactionManager must be declared. If the id is not "transactionManager", it must be set with <tx:annotation-driven>'s transaction-manager attribute … Continue reading Spring Transaction with @Transactional explained

About Spring ViewResolver

ViewResolver is very important component of Spring MVC. Without proper understanding, it is difficult to analyze MVC components, especially when taking over other's source code. The following explanations is based on Spring Framework 4.3.18. What is ViewResolver? (org.springframework.web.servlet.ViewResolver) ViewResolver is the translator which converts view name into View object View is the component which renders … Continue reading About Spring ViewResolver

Implementing REST API with Spring MVC

Spring MVC helps to build REST API server with minimum code. The crucial files are as follows. pom.xml (with dependency to spring framework and jackson 2) Spring context xml REST DAO class REST Controller class pom.xml Dependency to Spring framework and jackson2 is required spring context xml (servlet-context.xml) Above context don't have any view resolver. … Continue reading Implementing REST API with Spring MVC