spring-batch

How define a spring batch chunk in the tasklet with code

做~自己de王妃 提交于 2020-02-02 16:19:48
问题 I have a spring-batch xml-based configuration that should be migrated to annotation-based configuration. but I can't find any solution to define a chunk into the tasklet definition. There are my xml and code base decleration: <step id="files2Memory"> <tasklet> <chunk reader="pointFileReader" processor="pointFileProcessor" writer="pointFileWriter" commit-interval="50000"/> </tasklet> </step> public Step files2Memory() { return stepBuilders.get("files2Memory") .tasklet(new Tasklet() { @Override

How define a spring batch chunk in the tasklet with code

被刻印的时光 ゝ 提交于 2020-02-02 16:19:27
问题 I have a spring-batch xml-based configuration that should be migrated to annotation-based configuration. but I can't find any solution to define a chunk into the tasklet definition. There are my xml and code base decleration: <step id="files2Memory"> <tasklet> <chunk reader="pointFileReader" processor="pointFileProcessor" writer="pointFileWriter" commit-interval="50000"/> </tasklet> </step> public Step files2Memory() { return stepBuilders.get("files2Memory") .tasklet(new Tasklet() { @Override

Spring Batch Partitioning inject stepExecutionContext parameter in itemReader

随声附和 提交于 2020-02-02 06:51:06
问题 I am trying to learn Spring Batch with Partitioner. The issue is that I need to set the filenames dynamically from the Partitioner implementation. And I am trying to get it in the itemReader . But it gives filename null . My Spring Batch configuration: @Bean @StepScope public ItemReader<Transaction> itemReader(@Value("#{stepExecutionContext[filename]}") String filename) throws UnexpectedInputException, ParseException { FlatFileItemReader<Transaction> reader = new FlatFileItemReader

How do I set JobParameters in spring batch with spring-boot

此生再无相见时 提交于 2020-01-31 22:21:18
问题 I followed the guide at http://spring.io/guides/gs/batch-processing/ but it describes a job with no configurable parameters. I'm using Maven to build my project. I'm porting an existing job that I have defined in XML and would like to pass-in the jobParameters through the command. I tried the following : @Configuration @EnableBatchProcessing public class MyBatchConfiguration { // other beans ommited @Bean public Resource destFile(@Value("#{jobParameters[dest]}") String dest) { return new

How to trigger a scheduled Spring Batch Job?

不羁岁月 提交于 2020-01-31 04:48:07
问题 I want to be able to start my job with a REST controller, then when the job is started, it should run on a scheduled basis, until i stop it again with REST. So this is my Controller: @RestController public class LauncherController { @Autowired JobLauncher jobLauncher; @Autowired Job job; @RequestMapping("/launch") public String launch() throws Exception { ... jobLauncher.run(job, jobParameters); } This is some part of the Batch conf: @Configuration @EnableBatchProcessing @EnableScheduling

Accessing the ExecutionContext values in HeaderCallBack in Spring Batch

丶灬走出姿态 提交于 2020-01-30 12:03:06
问题 I'm trying to write a spring batch job which reads data from database and writes to FlatFile. I need to write the total records, total lines in the header of the FlatFile. Using the headerCallback property in Writer for that purpose. Problem statement: I'm setting the values in ExecutionContext in Processor and trying to retrieve the values in headerCallback of the Writer. But getting the values as null in headerCallback. Tried using ExecutionContextPromotionListener and also by injecting the

Spring: Getting FactoryBean object instead of FactoryBean.getObject()

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-29 03:39:09
问题 Short question: If I have class that impelemnts FactoryBean interface, how can I get from FactoryBean object itself instead of FactoryBean.getObject()? Long question: I have to use 3-rd party Spring based library which is hardly use FactoryBean interface. Right now I always must configure 2 beans: <!-- Case 1--> <bean id="XYZ" class="FactoryBean1" scope="prototype"> <property name="steps"> <bean class="FactoryBean2"> <property name="itemReader" ref="aName"/> </bean> </property> </bean> <bean

Spring Batch reader using generics

拈花ヽ惹草 提交于 2020-01-25 18:24:27
问题 I'm just new in the spring architecture and I am wondering if it is possible to use a generic T (o what you want) in an ItemStreamReader . Something like this: public class Reader implements ItemStreamReader<T extends SomeClass>{ public T read() { ....... } public void open() { ....... } public void update() { ....... } public void close() { ....... } } So I pass to the reader various objects that extends SomeClass . 回答1: this should work: public class Reader<T extends SomeClass> implements

Multiple Spring 3.2 scheduled tasks won't run in parallel

北慕城南 提交于 2020-01-25 00:26:26
问题 I have two scheduled tasks that I want to run in parallel. These two tasks execute a Spring Batch job. One every 15 seconds and the other ever 3 seconds. The problem is one will be running and the other is blocked until it finishes. I can't seem to find a similar question or example anywhere. Any ideas? Thanks, /w Here's a bit of my configuration. I'm using spring-task-3.2 and spring-batch-2.2 with Spring 3.2. This batch job is ran by the mappingRunScheduler . The other task runScheduler is

Spring Boot - Reconnect to a database after its restart

不打扰是莪最后的温柔 提交于 2020-01-24 21:48:26
问题 I have an Spring Batch application, which runs every 10 minutes. It gets some data from a REST API and then it saves these data on a database. Well, where is my problem now? Sometimes the database (Oracle) may restart, or go offline (no idea, really). But the application doesn't seem to reconnect to the database. It just stays on an idle mode. Spring Boot: 2.1.2.RELEASE The application.yml looks like this: app: database: jdbc-url: jdbc:oracle:thin:@<host>:<port>:<db> username: <username>