|
16 | 16 |
|
17 | 17 | package de.codecentric.batch.configuration;
|
18 | 18 |
|
| 19 | +import org.springframework.batch.core.configuration.JobRegistry; |
19 | 20 | import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
20 | 21 | import org.springframework.batch.core.converter.DefaultJobParametersConverter;
|
21 | 22 | import org.springframework.batch.core.converter.JobParametersConverter;
|
|
67 | 68 | @PropertySource("classpath:batch-web-spring-boot-autoconfigure.properties")
|
68 | 69 | @AutoConfigureAfter({ MetricsAutoConfiguration.class })
|
69 | 70 | @Import({ WebConfig.class, TaskExecutorBatchConfiguration.class, AutomaticJobRegistrarConfiguration.class,
|
70 |
| - BaseConfiguration.class, Jsr352BatchConfiguration.class, MetricsConfiguration.class, |
71 |
| - TaskExecutorConfiguration.class }) |
| 71 | + Jsr352BatchConfiguration.class, MetricsConfiguration.class, TaskExecutorConfiguration.class }) |
72 | 72 | @EnableConfigurationProperties({ BatchConfigurationProperties.class })
|
73 | 73 | public class BatchWebAutoConfiguration implements ApplicationListener<ContextRefreshedEvent>, Ordered {
|
74 | 74 |
|
75 |
| - @Autowired |
76 |
| - private BatchConfigurationProperties batchConfig; |
77 |
| - |
78 |
| - @Autowired |
79 |
| - private BaseConfiguration baseConfig; |
80 |
| - |
81 |
| - // ################### Listeners automatically added to each job ################################# |
82 |
| - |
83 |
| - @Bean |
84 |
| - public LoggingListener loggingListener() { |
85 |
| - return new LoggingListener(); |
86 |
| - } |
87 |
| - |
88 |
| - @Bean |
89 |
| - public LoggingAfterJobListener loggingAfterJobListener() { |
90 |
| - return new LoggingAfterJobListener(); |
91 |
| - } |
92 |
| - |
93 |
| - @Bean |
94 |
| - public ProtocolListener protocolListener() { |
95 |
| - return new ProtocolListener(); |
96 |
| - } |
97 |
| - |
98 |
| - @Bean |
99 |
| - public RunningExecutionTracker runningExecutionTracker() { |
100 |
| - return new RunningExecutionTracker(); |
101 |
| - } |
102 |
| - |
103 |
| - @Bean |
104 |
| - public RunningExecutionTrackerListener runningExecutionTrackerListener() { |
105 |
| - return new RunningExecutionTrackerListener(runningExecutionTracker()); |
106 |
| - } |
107 |
| - |
108 |
| - @Bean |
109 |
| - public AddListenerToJobService addListenerToJobService() { |
110 |
| - boolean addProtocolListener = batchConfig.getDefaultProtocol().isEnabled(); |
111 |
| - boolean addLoggingListener = batchConfig.getLogfileSeparation().isEnabled(); |
112 |
| - return new AddListenerToJobService(addProtocolListener, addLoggingListener, protocolListener(), |
113 |
| - runningExecutionTrackerListener(), loggingListener(), loggingAfterJobListener()); |
114 |
| - } |
115 |
| - |
116 |
| - @Override |
117 |
| - public void onApplicationEvent(ContextRefreshedEvent event) { |
118 |
| - baseConfig.jobRegistry().getJobNames().forEach(jobName -> { |
119 |
| - try { |
120 |
| - AbstractJob job = (AbstractJob) baseConfig.jobRegistry().getJob(jobName); |
121 |
| - this.addListenerToJobService().addListenerToJob(job); |
122 |
| - } catch (NoSuchJobException e) { |
123 |
| - throw new IllegalStateException(e); |
124 |
| - } |
125 |
| - }); |
126 |
| - } |
127 |
| - |
128 |
| - @Override |
129 |
| - public int getOrder() { |
130 |
| - return Ordered.LOWEST_PRECEDENCE; |
131 |
| - } |
| 75 | + @Autowired |
| 76 | + private BatchConfigurationProperties batchConfig; |
| 77 | + |
| 78 | + @Autowired |
| 79 | + private JobRegistry jobRegistry; |
| 80 | + |
| 81 | + // ################### Listeners automatically added to each job ################################# |
| 82 | + |
| 83 | + @Bean |
| 84 | + public LoggingListener loggingListener() { |
| 85 | + return new LoggingListener(); |
| 86 | + } |
| 87 | + |
| 88 | + @Bean |
| 89 | + public LoggingAfterJobListener loggingAfterJobListener() { |
| 90 | + return new LoggingAfterJobListener(); |
| 91 | + } |
| 92 | + |
| 93 | + @Bean |
| 94 | + public ProtocolListener protocolListener() { |
| 95 | + return new ProtocolListener(); |
| 96 | + } |
| 97 | + |
| 98 | + @Bean |
| 99 | + public RunningExecutionTracker runningExecutionTracker() { |
| 100 | + return new RunningExecutionTracker(); |
| 101 | + } |
| 102 | + |
| 103 | + @Bean |
| 104 | + public RunningExecutionTrackerListener runningExecutionTrackerListener() { |
| 105 | + return new RunningExecutionTrackerListener(runningExecutionTracker()); |
| 106 | + } |
| 107 | + |
| 108 | + @Bean |
| 109 | + public AddListenerToJobService addListenerToJobService() { |
| 110 | + boolean addProtocolListener = batchConfig.getDefaultProtocol().isEnabled(); |
| 111 | + boolean addLoggingListener = batchConfig.getLogfileSeparation().isEnabled(); |
| 112 | + return new AddListenerToJobService(addProtocolListener, addLoggingListener, protocolListener(), |
| 113 | + runningExecutionTrackerListener(), loggingListener(), loggingAfterJobListener()); |
| 114 | + } |
| 115 | + |
| 116 | + @Override |
| 117 | + public void onApplicationEvent(ContextRefreshedEvent event) { |
| 118 | + jobRegistry.getJobNames().forEach(jobName -> { |
| 119 | + try { |
| 120 | + AbstractJob job = (AbstractJob) jobRegistry.getJob(jobName); |
| 121 | + this.addListenerToJobService().addListenerToJob(job); |
| 122 | + } catch (NoSuchJobException e) { |
| 123 | + throw new IllegalStateException(e); |
| 124 | + } |
| 125 | + }); |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public int getOrder() { |
| 130 | + return Ordered.LOWEST_PRECEDENCE; |
| 131 | + } |
132 | 132 |
|
133 | 133 | @Bean
|
134 | 134 | @ConditionalOnMissingBean
|
135 | 135 | public JobParametersConverter jobParametersConverter() {
|
136 |
| - return new DefaultJobParametersConverter(); |
| 136 | + return new DefaultJobParametersConverter(); |
137 | 137 | }
|
138 | 138 |
|
139 | 139 | }
|
0 commit comments