5

I was wondering if it is possible to write a spring batch job that has a step that ONLY has a writer. I can't find any documentation on what is inherently necessary for a given step in the spring batch documentation.

I was hoping to do something like :

public class MyBatchConfiguration {

@Bean
public ItemWriter<myInfo> myWriter() {
    return new MyWriter();
}

@Bean
public Step myStep(StepBuilderFactory stepBuilderFactory,
        ItemWriter<? super Object> myWriter,
        PlatformTransactionManager transactionManager) {

    return stepBuilderFactory.get("myStep")
            .chunk(1)
            .writer(myWriter).
            transactionManager(transactionManager).
            build();
}

@Bean
public Job myBatch(JobBuilderFactory jobs, Step myStep, JobExecutionListener listener) {

    return jobs.get("myBatch")
            .incrementer(new RunIdIncrementer())
            .flow(exceptionReporterStep)
            .end()
            .listener(listener)
            .build();

}

}
Corey Schnedl
  • 165
  • 1
  • 3
  • 12
  • Possible duplicate of [How to write a spring batch step without an itemwriter](https://stackoverflow.com/questions/26202241/how-to-write-a-spring-batch-step-without-an-itemwriter) – Luca Basso Ricci May 23 '17 at 06:52

1 Answers1

5

In a word, no.

It seems like you likely should use a tasklet step rather than a "chunked" one.

@Bean
public Step myStep(StepBuilderFactory stepBuilderFactory,
        Tasklet myTasklet,
        PlatformTransactionManager transactionManager) {

    return stepBuilderFactory.get("myStep")
            .tasklet(myTasklet)
            .transactionManager(transactionManager)
            .build();
}
Dean Clark
  • 3,770
  • 1
  • 11
  • 26
  • Thank you! I haven't used Tasklets before, but this seems to be what I needed. I'll let you know if I run into any issues. – Corey Schnedl May 22 '17 at 17:03
  • Hey Dean, I don't really know how to go about debugging spring batch issues. I am getting an error saying "Exception in thread "main" java.lang.NoSuchMethodError" in my main method. Do you have any tips for debugging something like this? I don't think the job parameters are being created properly and I don't even know where to begin. – Corey Schnedl May 22 '17 at 18:54
  • 1
    Job params are likely not your issue. This sounds more like a typo or a classpath issue. I'd start with the following: 1) actually use debug in eclipse; 2) write a JUnit to recreate the issue; 3) add a complete stacktrace of your error to the question above – Dean Clark May 22 '17 at 19:05