File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
spring-boot-project/spring-boot-autoconfigure/src
main/java/org/springframework/boot/autoconfigure/batch
test/java/org/springframework/boot/autoconfigure/batch Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 2020
2121import javax .sql .DataSource ;
2222
23+ import org .springframework .batch .core .configuration .BatchConfigurationException ;
2324import org .springframework .batch .core .configuration .annotation .EnableBatchProcessing ;
2425import org .springframework .batch .core .configuration .support .DefaultBatchConfiguration ;
2526import org .springframework .batch .core .explore .JobExplorer ;
@@ -129,6 +130,13 @@ protected DataSource getDataSource() {
129130 return this .dataSource ;
130131 }
131132
133+ @ Bean
134+ @ ConditionalOnMissingBean
135+ @ Override
136+ public JobRepository jobRepository () throws BatchConfigurationException {
137+ return super .jobRepository ();
138+ }
139+
132140 @ Override
133141 protected PlatformTransactionManager getTransactionManager () {
134142 return this .transactionManager ;
Original file line number Diff line number Diff line change @@ -517,6 +517,13 @@ void defaultExecutionContextSerializerIsUsed() {
517517 });
518518 }
519519
520+ @ Test
521+ void defaultJobRepositoryIsNotCreatedWhenUserDefinedJobRepositoryBean () {
522+ this .contextRunner
523+ .withUserConfiguration (TestConfigurationWithJobRepository .class , EmbeddedDataSourceConfiguration .class )
524+ .run ((context ) -> assertThat (context ).hasSingleBean (TestJobRepository .class ));
525+ }
526+
520527 private JobLauncherApplicationRunner createInstance (String ... registeredJobNames ) {
521528 JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner (mock (JobLauncher .class ),
522529 mock (JobExplorer .class ), mock (JobRepository .class ));
@@ -596,6 +603,16 @@ static class TestConfiguration {
596603
597604 }
598605
606+ @ TestAutoConfigurationPackage (City .class )
607+ static class TestConfigurationWithJobRepository {
608+
609+ @ Bean
610+ TestJobRepository jobRepository () {
611+ return mock (TestJobRepository .class );
612+ }
613+
614+ }
615+
599616 @ Configuration (proxyBeanMethods = false )
600617 static class EntityManagerFactoryConfiguration {
601618
@@ -880,4 +897,8 @@ ExecutionContextSerializer executionContextSerializer() {
880897
881898 }
882899
900+ interface TestJobRepository extends JobRepository {
901+
902+ }
903+
883904}
You can’t perform that action at this time.
0 commit comments