Tag Archives: springbatch

Read file name when using MultiResourceItemReader in Springbatch

Springbatch provides MultiResourceItemReader to allow us to read all files in a folder: <bean id=”filenameReader” class=” org.springframework.batch.item.file.MultiResourceItemReader”> <property name=”resources” value=”file:SpringBatchReadFilename/tmp/*.csv” /> <property name=”delegate” ref=”filenameFlatReader” /> </bean> However, there maybe some cases that we want. Assume we have below 2 files and we want to output the filename in processor or writer. 20160402.csv id,value 4,d 20160403.csv id,value… Read More »

Springbatch cursor reader

Spingbatch default cursor reader reads data readily. It has below advantages over jdbctemplate: 1. Traditional jdbctemplate reader reads data in one time, which makes wait for a very long time. But cursor reader reads steadily, we don’t need to wait. 2. Jdbctemplate reads in one time, and put everything in memory. But cursor reader can avoid this… Read More »

Springbatch transaction manager

In SpringBatch, we can set transacational commit. This is very useful and important in batch job. Batch job won’t commit until a whole chunk process is done. Important part is that we should use DataSourceTransactionManager instead ofResourcelessTransactionManager. Below is the configuration supporting transaction commit in SpringBatch. <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=” http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd”> <import resource=”database.xml”/> <!– stored job-meta… Read More »

Read Spring Batch parameter to bean

After we add parameters to a job and run it. How do we get the parameter in the class? In config.xml, we add the following code: <bean id=”beanName” class=”com.pli.project.sba”> <property name=”emailFlag” value=”#{jobParameters[FAILURE_EMAIL]}”/> <bean> <bean class=”org.springframework.batch.core.scope.StepScope” />

Spring Batch run by Spring Batch Admin

The second way to run Spring Batch job is by Spring Batch Admin. It is more powerful. By SBA, we can execute/stop/monitor our batch job in web UI. I downloaded the SBA sample code from Spring Batch website and made it more simple version. I used the mysql to store the metadata. The metadata tables… Read More »

Spring Batch run by Console

There are two ways to run your batch job. First is to use console command. In order to do this, we need to compile the batch job, and saves all dependency jar in a lib file. We just write the following in the maven pom.xml(I refered this good example from mkyong.) <plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution>… Read More »

Spring Batch Basic

In last 2 weeks, I spent a lot of effort in researching in Spring Batch. This framework requires a lot of xml configuration. Below, I attached y passed code and explanation. My Spring Batch project refers from mkyong. database.xml If we want to autimatically create the metadata in database, we should add <jdbc:initialize-database> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:jdbc=”http://www.springframework.org/schema/jdbc”… Read More »