BATCH-2247: Added creation of a JobExplorer by default to address the inability to create a Map based JobExplorer using java config
This commit is contained in:
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.annotation;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.core.PooledEmbeddedDataSource;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -30,6 +26,9 @@ import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
public class DataSourceConfiguration {
|
||||
|
||||
@@ -49,7 +48,7 @@ public class DataSourceConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
return new PooledEmbeddedDataSource(new EmbeddedDatabaseFactory().getDatabase());
|
||||
return new EmbeddedDatabaseFactory().getDatabase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.annotation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
@@ -30,6 +26,7 @@ import org.springframework.batch.core.configuration.JobLocator;
|
||||
import org.springframework.batch.core.configuration.support.ApplicationContextFactory;
|
||||
import org.springframework.batch.core.configuration.support.AutomaticJobRegistrar;
|
||||
import org.springframework.batch.core.configuration.support.GenericApplicationContextFactory;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.job.builder.SimpleJobBuilder;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
@@ -40,6 +37,10 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -72,6 +73,8 @@ public class JobLoaderConfigurationTests {
|
||||
.toJobParameters());
|
||||
assertEquals(status, execution.getStatus());
|
||||
assertEquals(stepExecutionCount, execution.getStepExecutions().size());
|
||||
JobExplorer jobExplorer = context.getBean(JobExplorer.class);
|
||||
assertEquals(1, jobExplorer.getJobInstanceCount(jobName));
|
||||
context.close();
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.PooledEmbeddedDataSource;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
@@ -44,6 +45,7 @@ public class MapJobRepositoryConfigurationTests {
|
||||
JobLauncher jobLauncher;
|
||||
JobRepository jobRepository;
|
||||
Job job;
|
||||
JobExplorer jobExplorer;
|
||||
|
||||
@Test
|
||||
public void testRoseyScenario() throws Exception {
|
||||
@@ -65,11 +67,13 @@ public class MapJobRepositoryConfigurationTests {
|
||||
this.jobLauncher = context.getBean(JobLauncher.class);
|
||||
this.jobRepository = context.getBean(JobRepository.class);
|
||||
this.job = context.getBean(Job.class);
|
||||
this.jobExplorer = context.getBean(JobExplorer.class);
|
||||
|
||||
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
JobExecution repositoryJobExecution = jobRepository.getLastJobExecution(job.getName(), new JobParameters());
|
||||
assertEquals(jobExecution.getId(), repositoryJobExecution.getId());
|
||||
assertEquals("job", jobExplorer.getJobNames().iterator().next());
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user