Basically, Spring Batch Job runs in single thread. To increase the throughput, we need to parallelize the job by partitioning. The core architecture of Job partitioning is as follows. Partition Step : The wrapper of common Step with a partitioner and grid size (or partition size) Single Step : Common Step with a Reader, a … Continue reading Spring Batch tip – Partitioning
Tag: Spring framework
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
Simple ETL with Spring Batch
Spring Batch is literally a batch framework based on Spring Framework. I usually use it to develop a simple ETL(Extraction, Transaformation and Loading) program. In this post, I'll show you how to write a simple ETL program. (This sample is tested on Spring Batch 3.0.10) Prerequisites Database (MySQL or Oracle) Spring batch context database Spring … Continue reading Simple ETL with Spring Batch
Integrating Mybatis with Spring
Spring framework does not support Mybatis internally. Instead, mybatis-spring project supports integration of Mybatis with Spring. This article is based on Spring 4.3.16 and Mybatis 3.4.6. (As of writing this article, Spring 5.1.x still don't support Mybatis internally) You can download the sample project here. Test table for the sample Test Mybatis mapper xml Required … Continue reading Integrating Mybatis with Spring
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
Sending data from controller to view
Most dynamic web pages are composed of template and data. In Spring MVC, data is sent usually from controller to view. How to send data (from controller's point) Usually data is created in controller. The following is some ways to send data. (Not exhaustive explanation. More on RequestMapping handler method) To declare Model as parameter … Continue reading Sending data from controller to view
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