spring-batch , Spring GS - Creating a Batch Service missing output from db query

Spring GS - Creating a Batch Service missing output from db query


Tag: spring-batch

I have run the complete source for Getting Started - Creating a Batch Service

Knowing that the sample uses the memory-based database provided by the @EnableBatchProcessing, is the db query result expected or it will only be available if data will be persisted permanently?

After adding some debug lines, it seems that the DB query is executed first before the job gets executed. Was this the expected behavior?

Is there anything I'm missing here.

Thanks Alex


You aren't missing anything. This is related to issue number 8 for that guide (https://github.com/spring-guides/gs-batch-processing/issues/8). I just created a pull request to address this issue. You can view the PR here (https://github.com/spring-guides/gs-batch-processing/pull/9) until it's merged.

The PR has been merged and the guid has been updated. The new version should no longer have this issue.


how to use ExecutorChannel in spring integration?

Firstly thanks for attention i defined ExecutorChannel and task executor in my spring integration project, for async processing on messages with spring batch, as bellow : <bean id="ftpSessionFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory"> <property name="host" value="${ftp.server.ip}"/> <property name="port" value="${ftp.port}"/> <property name="username" value="${ftp.username}"/> <property name="password" value="${ftp.password}"/> <property name="clientMode"...

combine spring batch and spring integration?

thanks for attention,i defined a combine spring batch and spring integration project and communicate with ftp server to retrieve file and process on it and write on ftp, i am looking for a good architecture for my project, i designed an architecture with spring integration as bellow diagram: when retrieve...

@BeforeStep annotated method not being called

I am writing a spring batch job. But when this Archive class which implenets the tasklet interface in loaded, the method under the annotation @BeforeStep is not being called. Can anyone help me with this ? Thank You import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardCopyOption;...

WriterNotOpenException when using StepScope annotation in Spring Batch

I have a custom writer which works well ; however, I'd like to set the name of my output file through JobParameters instead of using a fixed string in my configuration. In order to do that, I added the @StepScope annotation and parameters, just like I did with my ItemReader....

Parallel job execution by setting job module count in Spring XD?

Since besides stream module, Spring-XD slap support to set module count number for batch jobs. For example, module.myjob.count=3. What will happen if the job is deployed in this way? Will the job be deployed on 3 different containers? Will the 3 copies of deployment execute in parallel? Does each copy...

Spring Batch Failure Listener Rollback

I am extending Spring Batch's ItemListenerSupport and overriding onProcessError() for dealing with error states. My problem is, I was expecting to be able to write to the database as part of my handling, but it seems its being included in the transaction for the batch and being rolled back. Is...

More than one tasklet in a step?

I have a tasklet setting some information into my JobContext, and another one checking some stuff to know if I can execute the next steps in my batch or not. Both tasklets work well if I use two different steps in my job flow, but I'd like to use these...

Execute database operations inside a chunck orientad step

I have a chunk oriented processor in the form "reader / processor / writer" called Job1. I have to execute database EJB operations after this job ends, if possible, in the same transaction. I have others jobs (implemented by Tasklets) that I could do this in a simply manner. I...

Overwriting spring-boot autoconfiguration

I'm a little bit confused with the behaviour of spring-boot when overwriting specific autoconfigurations. I like to partly overwrite the BatchAutoConfiguration, but I guess, my question is not specific to BatchAutoConfiguration. Actually, I just want to "overwrite" two methods of this class: public BatchDatabaseInitializer batchDatabaseInitializer() and public ExitCodeGenerator jobExecutionExitCodeGenerator(). Therefore,...

Spring Batch - Write multiple files based on records count

In spring batch, I have an requirement to read from the database and to write in a file, The no of rows allowed in a file is N, so if N+10 records are fetched then two files should be created containing N rows and 10 rows respectively. Can someone please...

log4j2.xml loaded but not applied [JVM argument]

I am trying to create a batch using spring batch, spring mvc and spring boot. And I am using log4j2 for logging. My goal is to load an external log4j2.xml configuration file thanks to JVM arguments like that -Dlog4j.configurationFile=file://C:\{path}\Workspace\demo-indexeur\config\log4j2.xml Spring boot detect my file (I have no error in the...

Spring Batch Add Custom Fields

I've never used Spring Batch before but it seems like a viable option for what I am attempting to accomplish. I have about 15 CSV files for 10 institutions that I need to process nightly. I am stashing the CSV into staging tables in an Oracle database. The CSV File...

How to initialize custom ItemReader?

I have created my custom ItemReader: @Component("pricereader") public class MyItemReader implements ItemReader<Price>{ @Override public Price read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { // TODO Auto-generated method stub return null; } } Calling it in a job thus defined: <batch:job id="job1"> <batch:step id="step1"> <batch:tasklet> <batch:chunk reader="pricereader" processor="priceprocessor" writer="pricewriter" commit-interval="1"/> </batch:tasklet>...

Spring batch FileItemWriter not creating file at correct path

I have a spring batch service containing a FileItemReader,FileItemProcessor and FileItemWriter.When creating the FileItemWriter I have to set the Resource that will be my output file. I am running the batch service on websphere on a Linux machine.The problem is if I set the resource as new FileSystemResource(new File("opt\temp1\myFile.txt")), the...

Spring batch diffrence between Multithreading vs partitioning

I cannot understand the difference between multi-threading and partitioning in Spring batch. the implementation is of course different. In partitioning you need to prepare the partitions then process it. I want to know what is the difference and witch one is more efficient way to process when the bottle neck...

Triggering spark jobs with REST

I have been of late trying out apache spark. My question is more specific to trigger spark jobs. Here I had posted question on understanding spark jobs. After getting dirty on jobs I moved on to my requirement. I have a REST end point where I expose API to trigger...

More than one Partitioner in a Spring batch job

I have two different files(both are different layouts) which i am splitting it as multiple files to make use of local step partitioning. so far i am handling with one file and i have created one custom partitioner class to make use of step partitioning. Now i want to include...

Persisting data larger then context limit across steps in spring batch

We are using spring batch to process large CSV file with 500K lines. Result of this processing is two things, one line presents one article object and with that we do not have any problems, after chunk is complete we do API call with list of processed articles (1000 per...

Spring Batch Item Reader is executing only once

Trying to implement Spring batch,but facing a strange problem,Our ItemReader class is executing only once. Here below is the detail. If we have 1000 rows in DB. Our Item reader fetch 1000 rows from DB,and pass list to ItemWriter ItemWriter successfully delete all items. Now ItemReader again tries to fetch...

Could not autowired Object in ItemStreamReader open method

I use Spring Batch with Spring Boot and here is a my main class. @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } Here is my configuration classes @Configuration public class AppConfig { @Bean public MyObject getObject() { return new MyObject(); } } @Configuration...

Spring Batch | MongoItemReader | How to pass JobParameters to mongo query?

How can I pass JobParameters to MongoItemReader query ? My ItemReader looks like :- @Bean public ItemReader<Person> PersonTenantBasedItemReader() { MongoItemReader<Person> reader = new MongoItemReader<Person>(); reader.setTemplate(mongoTemplate); reader.setTargetType((Class<? extends Person>) Person.class); reader.setQuery("{status:'XYZ',nextCheckpointDate:{$gte:?fromDate,$lte:?toDate}"); // !!!!I want to pass fromDate and toDate as job parameters. !!!! Map<String, Direction> sorts = new HashMap<String,...

Spring Batch : custom ItemReader

I have a Spring Batch project with a simple custom reader and writer. When i run the code i end up with an endeless loop printing the first item "item 1". What am i doing wrong? Here is my code: Reader.java public class Reader implements ItemReader<SimpleItem> { public SimpleItem read()...

how to run async batch job in batch-int:job-launching-gateway?

Firstly thanks for attention, I combined spring integration and spring batch in my project, i want to launch jobs in asynchronous mode in batch-int:job-launching-gateway, my means is that each message in input channel launch job in asynchronous and not wait util to complete the jobs,my code is: <batch-int:job-launching-gateway request-channel="outboundJobRequestChannel" reply-channel="jobLaunchReplyChannel"/>...

Change Spring Boot project to inherit custom dependency management

I have a small Spring Boot application which I must adapt to use a custom parent. Google finds lots of examples of how to migrate to Spring Boot, but I am at a loss as to migrate from Spring Boot (which I barely know to begin with). The reasons To...

What is the best approach for loading data from DB by multiple threads

I have some data in database in parent child relation, where my table is actually representing a forest of tree data structure. And the table structure is like: row1 parent: null row2 parent:row1 row3 parent:row2 row4 parent:row1 Now when I am loading this data from DB to my data structure...

how to run asynchronous queries with Spring

I need to use asynchronous queries using Spring framework. I use Cassandra and Java driver from Datastax. How can call the executeAsync method and get the results.

Spring batch for rules

I am new to Spring Batch. I need to run a nightly batch process that: reads records from table A, for each record in table A, run about 10 business rules with logic involve reading data from the database (in each rule) and write into table B in each rule,...

How do I use JdbcPagingItemReader in Spring Batch when my primary key is a string?

I've got some SQL data that I need to access with an ItemReader in Spring Batch. I thought that JdbcPagingItemReader / PagingQueryProvider would be the perfect fit. The table I'm selecting from has a primary key that is a composite of three columns: INTEGER, VARCHAR, and VARCHAR. And actually, for...

Exclusive batch jobs with javax.batch/jsr352

We have an application which does a lot of imports and exports - basically between CSV files and database tables. Some of the imports and exports are conflicting (you can't execute them simultaneously) for various reasons (like "legacy code"). We were looking into javax.batch. Conceptually it suits very well. But...

How to create Master Job to process multiple spring batch job?

We have multiple spring batch job.But Each of them needs to be started individually. Is there any way to create a Master Job or any controller in spring which will be responsible for executing all other batch jobs? So that we just have to execute the master job only,and all...

Spring Batch - Skip Record On Process

I wanted to skip some record on process. what i have tried is, i have created custom exception and throw the exception when i want to skip the record and its calling the Skip listener onSkipInProcess method.Its working fine. please find the configuration. <batch:chunk reader="masterFileItemReader" writer="masterFileWriter" processor="itemProcessor" commit-interval="5000" skip-limit="100000" >...

Failed to load ApplicationContext: Spring and junit

I'm writing unit tests for a Spring application. I have put my SpringContext.xml in pe.edu.upc.demo.configuration. SpringContext.xml: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd...

Batch job initialization fails on error while creating bean with name 'batchPropertyPostProcessor'

I'm trying to implement sample batch application using JSR-352 API and Spring Batch 3.0.4 as implementation. Batch job execution fails during initialization phase on error while creating bean with name 'batchPropertyPostProcessor': Exception in thread "main" javax.batch.operations.JobStartException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchPropertyPostProcessor': Injection of autowired dependencies failed; nested exception...

Spring GS - Creating a Batch Service missing output from db query

I have run the complete source for Getting Started - Creating a Batch Service Knowing that the sample uses the memory-based database provided by the @EnableBatchProcessing, is the db query result expected or it will only be available if data will be persisted permanently? After adding some debug lines, it...

Spring batch - ItemReader within another itemreader or Itemprocessor

Here is my requirement : Create a batch job that 1. Fetches discount programs from Discount table for specific search critieria 2. For each discount program fetched in Step1, Get sales records for sales that fit the discount program dates Get additional details for sales from some other tables 3....

How to set property using “tasklet ref” tag

I have a tasklet ValidarSituacaoTasklet that has an property situacao. This tasklet is used in 2 steps in distinct values for situacao. I declared steps as like: and the bean: <bean id="validarSituacaoTasklet" class="my.package.tasklet.ValidarSituacaoTasklet" scope="step"> </bean> I have to pass 'situacao' to tasklet . I tried: <step id="validaSituacaoStep"> <tasklet ref="validarSituacaoTasklet ">...

Access @JobScope bean in spring batch with partitioned step

Is there a way to access bean which is defined as @JobScope in partitioned step? We defined http client bean as @JobScope since it is unique per job but dynamically created and we need it in slave steps to issue post requests. When we autowire everything we get Error creating...

Setting EXIT_MESSAGE in batch_job_execution

One of the step in my job is having an exception and hence the job is failing with the EXIT_CODE "FAILED". Now I want to set the EXIT_MESSAGE as well, I did the following but the message is not getting set.. Any ideas?? chunkContext.getStepContext().getStepExecution().getJobExecution().setExitStatus(ExitStatus.FAILED); ExitStatus es = jobExecution.getExitStatus(); es =...

How to show sum of transaction amounts and count in a header tag in an output xml generated in Spring batch?

I need to create a xml file from some tables (some transactions) using Spring Batch. I need to add a header to the xml containing the sum of total transaction amount and a few details which needs some data that is calculated during processing in batch. I know header could...

Removing duplicate code from Spring job configuration

Below is my step configuration - <beans:bean id="myInputFileReader" class="com.rbos.fm.risk.batch.spring.reader.InputFileReader" scope="step"> <beans:property name="delegate"> <beans:bean class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> <beans:property name="resource" ref="inputFileSystemResource" /> <beans:property name="linesToSkip" value="1" /> <beans:property name="lineMapper"> <beans:bean...

Spring Batch reader file by file

I'm developing a Spring webapp, using spring boot and spring batch frameworks. We have a set of complex & different json files, and we need to: read each file slightly modify its content finally store them in mongodb. The question: It makes sense to use spring batch for this task?...

spring integration vs spring batch [on hold]

We have application where we are receiving file every day and it needs to be parsed and persist in db. File has 5000 record. Should we use spring batch or spring integration? And why? we do need to skip bad record and audit them....

How to call a specific method of a tasklet

In a job context there are an 'method' parameter so a could call directly an tasklet method as said in the documentation "If the tasklet is specified as a bean definition, then a method can be specified and a POJO will be adapted to the Tasklet interface. The method suggested...

Running a specific spring batch job amongst several jobs contained withing a spring boot fat jar

I am trying to run a spring batch job from a spring boot fat jar and I am having issues referencing the nested jars. Here is the command I use: java -cp bignibou-batch-core/build/libs/bignibou-batch-core.jar:lib/spring-batch-core-3.0.3.RELEASE.jar org.springframework.batch.core.launch.support.CommandLineJobRunner com.bignibou.batch.configuration.BatchConfiguration mailingJob Notice how I reference the nested spring batch jar using the colon. Why is...

FlatFileParseException Spring batch

I am getting flat file parse exception when i use FlatFileItemReader in my job configuration. Actually it was working fine, but with recent files its throwing error. org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1 in resource=[URL [file:/prod/users/cdi/crh537/Java_All/input/xaaaaa]], input=[16910203315393417SEVAN Q DANG18711 PARK GROVE [email protected]MAR CL197311192013042504Closed (zero balance DDA)220PUSA] The main difference is...

Spring Batch Execution Status Backed by Database

From the Spring Guides: For starters, the @EnableBatchProcessing annotation adds many critical beans that support jobs and saves you a lot of leg work. This example uses a memory-based database (provided by @EnableBatchProcessing), meaning that when it’s done, the data is gone. How can I make the execution state backed...

Spring batch generating reports

I would like to generate a summary report at the end of my batch execution. For ex: I have an ItemProcessor which receives accountId. for every accountId: get MarketplaceId's for every marketplaceId: call real time availability At the end of batch execution I need to provide a nice summary in...

How does Spring Batch manage transactions (with possibly multiple datasources)?

I would like some information about the data flow in a Spring Batch processing but fail to find what I am looking for on the Internet (despite some useful questions on this site). I am trying to establish standards to use Spring Batch in our company and we are wondering...

how to best approach to use spring batch annotation or xml files ?

firstly, thanks for attention,in my spring batch project defined many jobs , for example: <batch:job id="helloWorldJob1" job-repository="jobRepository"> <batch:step id="step1" > <batch:tasklet> <batch:chunk reader="itemReader1" writer="itemWriter1" processor="itemProcessor1"> </batch:chunk> </batch:tasklet> </batch:step> </batch:job> <batch:job id="helloWorldJob2" job-repository="jobRepository"> <batch:step id="step1" > <batch:tasklet> <batch:chunk...

To read Excel can we use Spring batch?

I want to know if it is possible to use Spring Batch, in order to read from an file Excel and save it in Database. remark : the content of file Excel chang every 2 hours. And if it is not possible with Spring Batch, what other solution can i...