|
43 | 43 | import org.springframework.batch.core.job.AbstractJob;
|
44 | 44 | import org.springframework.batch.core.launch.JobLauncher;
|
45 | 45 | import org.springframework.batch.core.launch.JobOperator;
|
| 46 | +import org.springframework.batch.core.repository.ExecutionContextSerializer; |
46 | 47 | import org.springframework.batch.core.repository.JobRepository;
|
| 48 | +import org.springframework.batch.core.repository.dao.DefaultExecutionContextSerializer; |
| 49 | +import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer; |
47 | 50 | import org.springframework.beans.BeansException;
|
48 | 51 | import org.springframework.beans.factory.annotation.Autowired;
|
49 | 52 | import org.springframework.beans.factory.config.BeanPostProcessor;
|
|
98 | 101 | * @author Vedran Pavic
|
99 | 102 | * @author Kazuki Shimizu
|
100 | 103 | * @author Mahmoud Ben Hassine
|
| 104 | + * @author Lars Uffmann |
101 | 105 | */
|
102 | 106 | @ExtendWith(OutputCaptureExtension.class)
|
103 | 107 | class BatchAutoConfigurationTests {
|
@@ -462,6 +466,27 @@ void whenTheUserDefinesAJobNameThatDoesNotExistWithRegisteredJobFailsFast() {
|
462 | 466 | .withMessage("No job found with name 'three'");
|
463 | 467 | }
|
464 | 468 |
|
| 469 | + @Test |
| 470 | + void customExecutionContextSerializerIsUsed() { |
| 471 | + this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class) |
| 472 | + .withUserConfiguration(CustomExecutionContextConfiguration.class) |
| 473 | + .run((context) -> { |
| 474 | + assertThat(context).hasSingleBean(Jackson2ExecutionContextStringSerializer.class); |
| 475 | + assertThat(context.getBean(SpringBootBatchConfiguration.class).getExecutionContextSerializer()) |
| 476 | + .isInstanceOf(Jackson2ExecutionContextStringSerializer.class); |
| 477 | + }); |
| 478 | + } |
| 479 | + |
| 480 | + @Test |
| 481 | + void defaultExecutionContextSerializerIsUsed() { |
| 482 | + this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class) |
| 483 | + .run((context) -> { |
| 484 | + assertThat(context).doesNotHaveBean(ExecutionContextSerializer.class); |
| 485 | + assertThat(context.getBean(SpringBootBatchConfiguration.class).getExecutionContextSerializer()) |
| 486 | + .isInstanceOf(DefaultExecutionContextSerializer.class); |
| 487 | + }); |
| 488 | + } |
| 489 | + |
465 | 490 | private JobLauncherApplicationRunner createInstance(String... registeredJobNames) {
|
466 | 491 | JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner(mock(JobLauncher.class),
|
467 | 492 | mock(JobExplorer.class), mock(JobRepository.class));
|
@@ -777,4 +802,14 @@ BatchConversionServiceCustomizer anotherBatchConversionServiceCustomizer() {
|
777 | 802 |
|
778 | 803 | }
|
779 | 804 |
|
| 805 | + @Configuration(proxyBeanMethods = false) |
| 806 | + static class CustomExecutionContextConfiguration { |
| 807 | + |
| 808 | + @Bean |
| 809 | + ExecutionContextSerializer executionContextSerializer() { |
| 810 | + return new Jackson2ExecutionContextStringSerializer(); |
| 811 | + } |
| 812 | + |
| 813 | + } |
| 814 | + |
780 | 815 | }
|
0 commit comments