11/*
2- * Copyright 2012-2023 the original author or authors.
2+ * Copyright 2012-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
5252import org .springframework .batch .item .database .support .DefaultDataFieldMaxValueIncrementerFactory ;
5353import org .springframework .batch .support .DatabaseType ;
5454import org .springframework .beans .BeansException ;
55- import org .springframework .beans .factory .annotation .Autowired ;
5655import org .springframework .context .ApplicationContext ;
5756import org .springframework .context .ApplicationContextAware ;
5857import org .springframework .context .annotation .Bean ;
115114@ Import (ScopeConfiguration .class )
116115public class DefaultBatchConfiguration implements ApplicationContextAware {
117116
118- @ Autowired
119117 protected ApplicationContext applicationContext ;
120118
121- private final JobRegistry jobRegistry = new MapJobRegistry ();
122-
123119 @ Override
124120 public void setApplicationContext (ApplicationContext applicationContext ) throws BeansException {
125121 this .applicationContext = applicationContext ;
@@ -152,10 +148,28 @@ public JobRepository jobRepository() throws BatchConfigurationException {
152148 }
153149 }
154150
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 )
156158 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 {
157171 TaskExecutorJobLauncher taskExecutorJobLauncher = new TaskExecutorJobLauncher ();
158- taskExecutorJobLauncher .setJobRepository (jobRepository () );
172+ taskExecutorJobLauncher .setJobRepository (jobRepository );
159173 taskExecutorJobLauncher .setTaskExecutor (getTaskExecutor ());
160174 try {
161175 taskExecutorJobLauncher .afterPropertiesSet ();
@@ -189,17 +203,40 @@ public JobExplorer jobExplorer() throws BatchConfigurationException {
189203
190204 @ Bean
191205 public JobRegistry jobRegistry () throws BatchConfigurationException {
192- return this . jobRegistry ; // FIXME returning a new instance here does not work
206+ return new MapJobRegistry ();
193207 }
194208
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 )
196217 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 {
197234 JobOperatorFactoryBean jobOperatorFactoryBean = new JobOperatorFactoryBean ();
198235 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 );
203240 try {
204241 jobOperatorFactoryBean .afterPropertiesSet ();
205242 return jobOperatorFactoryBean .getObject ();
@@ -209,16 +246,29 @@ public JobOperator jobOperator() throws BatchConfigurationException {
209246 }
210247 }
211248
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+
212261 /**
213262 * Defines a {@link JobRegistryBeanPostProcessor} bean.
214263 * @return a {@link JobRegistryBeanPostProcessor} bean
215264 * @throws BatchConfigurationException if unable to register the bean
216- * @since 5.1
265+ * @since 5.2
217266 */
218267 @ Bean
219- public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor () throws BatchConfigurationException {
268+ public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor (JobRegistry jobRegistry )
269+ throws BatchConfigurationException {
220270 JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor ();
221- jobRegistryBeanPostProcessor .setJobRegistry (jobRegistry () );
271+ jobRegistryBeanPostProcessor .setJobRegistry (jobRegistry );
222272 try {
223273 jobRegistryBeanPostProcessor .afterPropertiesSet ();
224274 return jobRegistryBeanPostProcessor ;
0 commit comments