1
1
/*
2
- * Copyright 2012-2023 the original author or authors.
2
+ * Copyright 2012-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
52
52
import org .springframework .batch .item .database .support .DefaultDataFieldMaxValueIncrementerFactory ;
53
53
import org .springframework .batch .support .DatabaseType ;
54
54
import org .springframework .beans .BeansException ;
55
- import org .springframework .beans .factory .annotation .Autowired ;
56
55
import org .springframework .context .ApplicationContext ;
57
56
import org .springframework .context .ApplicationContextAware ;
58
57
import org .springframework .context .annotation .Bean ;
115
114
@ Import (ScopeConfiguration .class )
116
115
public class DefaultBatchConfiguration implements ApplicationContextAware {
117
116
118
- @ Autowired
119
117
protected ApplicationContext applicationContext ;
120
118
121
- private final JobRegistry jobRegistry = new MapJobRegistry ();
122
-
123
119
@ Override
124
120
public void setApplicationContext (ApplicationContext applicationContext ) throws BeansException {
125
121
this .applicationContext = applicationContext ;
@@ -152,10 +148,28 @@ public JobRepository jobRepository() throws BatchConfigurationException {
152
148
}
153
149
}
154
150
155
- @ Bean
151
+ /**
152
+ * Define a job launcher.
153
+ * @return a job launcher
154
+ * @throws BatchConfigurationException if unable to configure the default job launcher
155
+ * @deprecated Since 5.2. Use {@link #jobLauncher(JobRepository)} instead
156
+ */
157
+ @ Deprecated (forRemoval = true )
156
158
public JobLauncher jobLauncher () throws BatchConfigurationException {
159
+ return jobLauncher (jobRepository ());
160
+ }
161
+
162
+ /**
163
+ * Define a job launcher bean.
164
+ * @param jobRepository the job repository
165
+ * @return a job launcher
166
+ * @throws BatchConfigurationException if unable to configure the default job launcher
167
+ * @since 5.2
168
+ */
169
+ @ Bean
170
+ public JobLauncher jobLauncher (JobRepository jobRepository ) throws BatchConfigurationException {
157
171
TaskExecutorJobLauncher taskExecutorJobLauncher = new TaskExecutorJobLauncher ();
158
- taskExecutorJobLauncher .setJobRepository (jobRepository () );
172
+ taskExecutorJobLauncher .setJobRepository (jobRepository );
159
173
taskExecutorJobLauncher .setTaskExecutor (getTaskExecutor ());
160
174
try {
161
175
taskExecutorJobLauncher .afterPropertiesSet ();
@@ -189,17 +203,40 @@ public JobExplorer jobExplorer() throws BatchConfigurationException {
189
203
190
204
@ Bean
191
205
public JobRegistry jobRegistry () throws BatchConfigurationException {
192
- return this . jobRegistry ; // FIXME returning a new instance here does not work
206
+ return new MapJobRegistry ();
193
207
}
194
208
195
- @ Bean
209
+ /**
210
+ * Define a job operator.
211
+ * @return a job operator
212
+ * @throws BatchConfigurationException if unable to configure the default job operator
213
+ * @deprecated Since 5.2. Use
214
+ * {@link #jobOperator(JobRepository, JobExplorer, JobRegistry, JobLauncher)} instead
215
+ */
216
+ @ Deprecated (forRemoval = true )
196
217
public JobOperator jobOperator () throws BatchConfigurationException {
218
+ return jobOperator (jobRepository (), jobExplorer (), jobRegistry (), jobLauncher ());
219
+ }
220
+
221
+ /**
222
+ * Define a job operator bean.
223
+ * @param jobRepository a job repository
224
+ * @param jobExplorer a job explorer
225
+ * @param jobRegistry a job registry
226
+ * @param jobLauncher a job launcher
227
+ * @return a job operator
228
+ * @throws BatchConfigurationException if unable to configure the default job operator
229
+ * @since 5.2
230
+ */
231
+ @ Bean
232
+ public JobOperator jobOperator (JobRepository jobRepository , JobExplorer jobExplorer , JobRegistry jobRegistry ,
233
+ JobLauncher jobLauncher ) throws BatchConfigurationException {
197
234
JobOperatorFactoryBean jobOperatorFactoryBean = new JobOperatorFactoryBean ();
198
235
jobOperatorFactoryBean .setTransactionManager (getTransactionManager ());
199
- jobOperatorFactoryBean .setJobRepository (jobRepository () );
200
- jobOperatorFactoryBean .setJobExplorer (jobExplorer () );
201
- jobOperatorFactoryBean .setJobRegistry (jobRegistry () );
202
- jobOperatorFactoryBean .setJobLauncher (jobLauncher () );
236
+ jobOperatorFactoryBean .setJobRepository (jobRepository );
237
+ jobOperatorFactoryBean .setJobExplorer (jobExplorer );
238
+ jobOperatorFactoryBean .setJobRegistry (jobRegistry );
239
+ jobOperatorFactoryBean .setJobLauncher (jobLauncher );
203
240
try {
204
241
jobOperatorFactoryBean .afterPropertiesSet ();
205
242
return jobOperatorFactoryBean .getObject ();
@@ -209,16 +246,29 @@ public JobOperator jobOperator() throws BatchConfigurationException {
209
246
}
210
247
}
211
248
249
+ /**
250
+ * Defines a {@link JobRegistryBeanPostProcessor}.
251
+ * @return a {@link JobRegistryBeanPostProcessor}
252
+ * @throws BatchConfigurationException if unable to register the bean
253
+ * @since 5.1
254
+ * @deprecated Use {@link #jobRegistryBeanPostProcessor(JobRegistry)} instead
255
+ */
256
+ @ Deprecated (forRemoval = true )
257
+ public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor () throws BatchConfigurationException {
258
+ return jobRegistryBeanPostProcessor (jobRegistry ());
259
+ }
260
+
212
261
/**
213
262
* Defines a {@link JobRegistryBeanPostProcessor} bean.
214
263
* @return a {@link JobRegistryBeanPostProcessor} bean
215
264
* @throws BatchConfigurationException if unable to register the bean
216
- * @since 5.1
265
+ * @since 5.2
217
266
*/
218
267
@ Bean
219
- public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor () throws BatchConfigurationException {
268
+ public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor (JobRegistry jobRegistry )
269
+ throws BatchConfigurationException {
220
270
JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor ();
221
- jobRegistryBeanPostProcessor .setJobRegistry (jobRegistry () );
271
+ jobRegistryBeanPostProcessor .setJobRegistry (jobRegistry );
222
272
try {
223
273
jobRegistryBeanPostProcessor .afterPropertiesSet ();
224
274
return jobRegistryBeanPostProcessor ;
0 commit comments