spring-batch

How do I get Spring Batch Job ContextId in ItemProcessor or ItemWriter?

*爱你&永不变心* 提交于 2019-11-30 02:48:46
问题 I need to store Job ExecutionId as one of the fields of Entity. (I am using JpaItemWriter) One of topic here explains from StepExcecution, I can get StepContext -> JobExecution. In that case how to get StepExecution? (I have no need to pass any data from one step to another, all I need is JobExecuionId) Thanks for help, Muneer Ahmed 回答1: We can set the scope as job using @Scope("job") of Itemprocessor and can easly get JobExecution using @Value("#{jobExecution}") expression as below. @Service

Is there a way to integrate spring-batch-admin and spring-boot properly?

瘦欲@ 提交于 2019-11-30 01:57:05
问题 According to the documentation spring batch admin is very easy to embed into the existing application. Simply copying web.xml and index.jsp then adding needed dependencies is enough getting it to work. But if I want to use it in an existing spring boot project it getting worse. According to this example the configuration is a bit hacky but it works. UNTIL I try to use @EnableBatchProcessing annotation in my configuriton bean. Then I get the following exception. Exception in thread "main" org

Spring-Batch: how do I return a custom Job exit code from a StepListener

一笑奈何 提交于 2019-11-30 00:22:39
问题 The issue is this: I have a Spring Batch job with a single step. This step is called multiple times. If every time it's called everything works ok (no Exceptions) the Job status is "COMPLETED". If something bad happends at least in one of the executions of the Step (an exception is thrown) I've configured a StepListener that changes the exit code to FAILED: public class SkipCheckingListener extends StepExecutionListenerSupport { public ExitStatus afterStep(StepExecution stepExecution) {

Transaction Issue with Spring Batch JobRepository in Unit Test

旧城冷巷雨未停 提交于 2019-11-29 21:58:12
问题 Could anybody help me figure out the solution to the following exception, I guess I just don't quite understand the Transaction Propagation mechanism, which hinder me from understanding the true meaning of the exception message shown below, so please, help me understanding the whole thing, thank you so much indeed! java.lang.IllegalStateException: Existing transaction detected in JobRepository. Please fix this and try again (e.g. remove @Transactional annotations from client). at org

How Does Spring Batch Step Scope Work

狂风中的少年 提交于 2019-11-29 21:50:38
I have a requirement where I need to process files based on the rest call in which I get the name of the file, I am adding it to the job parameter and using it while creating the beans. I am creating step scope Beans for (reader,writer) and using the job parameter.I am starting the job in a new thread as I am using asynchronus task exceutor to launch the job and my question is how will the beans be created by spring when we define @StepScope jobParametersBuilder.addString("fileName", request.getFileName()); jobExecution = jobLauncher.run(job, jobParametersBuilder.toJobParameters()); @Bean

What's the equivalent of Python's Celery project for Java?

情到浓时终转凉″ 提交于 2019-11-29 20:48:26
I am trying to find an equivalent of Celery project for Java environment, I have looked at Spring Batch, but are there any better alternatives for distributed task queues. Thanks. Adam Gent What Celery is doing is very much akin to EIP , and SEDA with convenient task scheduling... (all you have left to do is add some DB, and async HTTP networking and you have got a complete enterprise quality stack). Basically in Java there is the Spring way, the Java EE way, and the Hadoop way: Spring: Spring Integration + Spring Batch + RabbitMQ Java EE: Mule + Quartz or EJB Scheduling + HornetMQ Hadoop:

Spring Batch Admin + Spring Boot - Ambiguous mapping. Cannot map 'org.springframework.batch.admin.web.JobController#1' method

瘦欲@ 提交于 2019-11-29 18:14:56
I am trying to have Spring Batch Admin UI using spring-batch-admin-samples project. My job uses Spring Boot and I have changed my main application class to be deployable to Weblogic using this link . So application class looks like, @SpringBootApplication(exclude = { HypermediaAutoConfiguration.class, MultipartAutoConfiguration.class }) @EnableBatchAdmin public class MyApplication extends SpringBootServletInitializer implements WebApplicationInitializer { @Override protected SpringApplicationBuilder configure( SpringApplicationBuilder builder) { return configureApplication(builder); } public

SpringBatch - Get Line Number on FieldSetMapper

眉间皱痕 提交于 2019-11-29 17:02:42
I need to get the line number into the FieldSet Mapper. How can I do this? I want to use the lineNumber as a field of my resulting object produced by the Mapper. <beans:bean id="fileReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> <beans:property name="resource" value="file:${batch.source}"/> <beans:property name="lineMapper"> <beans:bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper"> <beans:property name="lineTokenizer"> <beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"> <beans:property name=

Spring Batch: How to setup a FlatFileItemReader to read a json file?

核能气质少年 提交于 2019-11-29 16:38:23
My approach so far: @Bean FlatFileItemReader<Blub> flatFileItemReader() { FlatFileItemReader<Blub> reader = new FlatFileItemReader<>(); reader.setResource(new FileSystemResource("test.json")); JsonLineMapper lineMapper = new JsonLineMapper(); reader.setLineMapper(lineMapper); return reader; } The challenge is: reader.setLineMapper() cannot use the JsonLineMapper . How to use the JsonLineMapper properly? How to setup a FlatFileItemReader to read a json file? It depends on the format of your json file: 1. Each line is a json object (known as NDJson ) For example: {object1} {object2} then you

Spring Batch-How to process multiple records at the same time in the processor?

风流意气都作罢 提交于 2019-11-29 16:21:42
I have a file to parse and process records from. It is working fine as line-by-line (parsing one record at a time). My requirement is I've to parse thru multiple line and fetch the required information from each records and then after combining the fetched info from all the records, I call a service to perform business logic. I have to perform this logic inside my Processor class. The data looks like as below example: 001 123456 987654321551580 Wayne DR 1 001 123456 987654321552APT 786 1 001 123456 987654321553LOS ANGELES 1 001 123456 987654321554CA 1 001 123456 98765432155590001 1 The data