Skip to content

Commit 6a0eb90

Browse files
wilkinsonaPhillip Webb
authored andcommitted
Upgrade to Spring Batch 3.0.1
Due to a mistake in Spring Batch 3.0.0 it has been necessary to introduce a breaking API change (the addition of BatchConfigurer.getJobExplorer()) in the 3.0.1 release. This commit updates Boot to use 3.0.1 and modifies the Batch auto-configuration and associated tests to implement the new method.
1 parent f7b7b1c commit 6a0eb90

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
2525
import org.springframework.batch.core.configuration.annotation.BatchConfigurer;
26+
import org.springframework.batch.core.explore.JobExplorer;
27+
import org.springframework.batch.core.explore.support.JobExplorerFactoryBean;
2628
import org.springframework.batch.core.launch.JobLauncher;
2729
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
2830
import org.springframework.batch.core.repository.JobRepository;
@@ -36,6 +38,7 @@
3638
* Basic {@link BatchConfigurer} implementation.
3739
*
3840
* @author Dave Syer
41+
* @author Andy Wilkinson
3942
*/
4043
@Component
4144
public class BasicBatchConfigurer implements BatchConfigurer {
@@ -52,6 +55,8 @@ public class BasicBatchConfigurer implements BatchConfigurer {
5255

5356
private JobLauncher jobLauncher;
5457

58+
private JobExplorer jobExplorer;
59+
5560
/**
5661
* Create a new {@link BasicBatchConfigurer} instance.
5762
* @param dataSource the underlying data source
@@ -86,18 +91,31 @@ public JobLauncher getJobLauncher() {
8691
return this.jobLauncher;
8792
}
8893

94+
@Override
95+
public JobExplorer getJobExplorer() throws Exception {
96+
return this.jobExplorer;
97+
}
98+
8999
@PostConstruct
90100
public void initialize() {
91101
try {
92102
this.transactionManager = createTransactionManager();
93103
this.jobRepository = createJobRepository();
94104
this.jobLauncher = createJobLauncher();
105+
this.jobExplorer = createJobExplorer();
95106
}
96107
catch (Exception ex) {
97108
throw new IllegalStateException("Unable to initialize Spring Batch", ex);
98109
}
99110
}
100111

112+
private JobExplorer createJobExplorer() throws Exception {
113+
JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean();
114+
jobExplorerFactoryBean.setDataSource(this.dataSource);
115+
jobExplorerFactoryBean.afterPropertiesSet();
116+
return jobExplorerFactoryBean.getObject();
117+
}
118+
101119
private JobLauncher createJobLauncher() throws Exception {
102120
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
103121
jobLauncher.setJobRepository(getJobRepository());

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ public JobLauncher getJobLauncher() throws Exception {
248248
return launcher;
249249
}
250250

251-
@Bean
252-
public JobExplorer jobExplorer() throws Exception {
251+
@Override
252+
public JobExplorer getJobExplorer() throws Exception {
253253
MapJobExplorerFactoryBean explorer = new MapJobExplorerFactoryBean(
254254
this.factory);
255255
explorer.afterPropertiesSet();

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunnerTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.batch.repeat.RepeatStatus;
4040
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
4141
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
42-
import org.springframework.context.annotation.Bean;
4342
import org.springframework.context.annotation.Configuration;
4443
import org.springframework.core.task.SyncTaskExecutor;
4544
import org.springframework.transaction.PlatformTransactionManager;
@@ -177,8 +176,8 @@ public JobLauncher getJobLauncher() throws Exception {
177176
return launcher;
178177
}
179178

180-
@Bean
181-
public JobExplorer jobExplorer() throws Exception {
179+
@Override
180+
public JobExplorer getJobExplorer() throws Exception {
182181
return new MapJobExplorerFactoryBean(this.jobRepositoryFactory).getObject();
183182
}
184183
}

spring-boot-dependencies/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<spock.version>0.7-groovy-2.0</spock.version>
9999
<spring.version>4.0.5.RELEASE</spring.version>
100100
<spring-amqp.version>1.3.5.RELEASE</spring-amqp.version>
101-
<spring-batch.version>3.0.0.RELEASE</spring-batch.version>
101+
<spring-batch.version>3.0.1.RELEASE</spring-batch.version>
102102
<spring-data-releasetrain.version>Dijkstra-SR1</spring-data-releasetrain.version>
103103
<spring-hateoas.version>0.14.0.RELEASE</spring-hateoas.version>
104104
<spring-integration.version>4.0.2.RELEASE</spring-integration.version>

0 commit comments

Comments
 (0)