From aa1f87420584192157a2f62fda6634fe22e48a8a Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 25 Oct 2016 11:59:32 +0100 Subject: [PATCH] Use @Component for listener --- README.adoc | 2 -- .../src/main/java/hello/BatchConfiguration.java | 13 ++----------- .../hello/JobCompletionNotificationListener.java | 1 + 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/README.adoc b/README.adoc index c5129c260e..ba75a93262 100644 --- a/README.adoc +++ b/README.adoc @@ -121,8 +121,6 @@ The first method defines the job and the second one defines a single step. Jobs In this job definition, you need an incrementer because jobs use a database to maintain execution state. You then list each step, of which this job has only one step. The job ends, and the Java API produces a perfectly configured job. -The `listener()` method lets you hook into the engine and detect when the job is complete, triggering the verification of results. - In the step definition, you define how much data to write at a time. In this case, it writes up to ten records at a time. Next, you configure the reader, processor, and writer using the injected bits from earlier. NOTE: chunk() is prefixed `` because it's a generic method. This represents the input and output types of each "chunk" of processing, and lines up with `ItemReader` and `ItemWriter`. diff --git a/complete/src/main/java/hello/BatchConfiguration.java b/complete/src/main/java/hello/BatchConfiguration.java index 388c91e254..8c776cd02b 100644 --- a/complete/src/main/java/hello/BatchConfiguration.java +++ b/complete/src/main/java/hello/BatchConfiguration.java @@ -65,21 +65,12 @@ public class BatchConfiguration { } // end::readerwriterprocessor[] - // tag::listener[] - - @Bean - public JobExecutionListener listener() { - return new JobCompletionNotificationListener(new JdbcTemplate(dataSource)); - } - - // end::listener[] - // tag::jobstep[] @Bean - public Job importUserJob() { + public Job importUserJob(JobCompletionNotificationListener listener) { return jobBuilderFactory.get("importUserJob") .incrementer(new RunIdIncrementer()) - .listener(listener()) + .listener(listener) .flow(step1()) .end() .build(); diff --git a/complete/src/main/java/hello/JobCompletionNotificationListener.java b/complete/src/main/java/hello/JobCompletionNotificationListener.java index a066e0399c..e66aca5da8 100644 --- a/complete/src/main/java/hello/JobCompletionNotificationListener.java +++ b/complete/src/main/java/hello/JobCompletionNotificationListener.java @@ -15,6 +15,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Component; +@Component public class JobCompletionNotificationListener extends JobExecutionListenerSupport { private static final Logger log = LoggerFactory.getLogger(JobCompletionNotificationListener.class);