Use @Component for listener
This commit is contained in:
parent
96d26d3ca4
commit
aa1f874205
@ -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 `<Person,Person>` because it's a generic method. This represents the input and output types of each "chunk" of processing, and lines up with `ItemReader<Person>` and `ItemWriter<Person>`.
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user