Remove JobExplorer bean registration from the default batch configuration
Resolves #4825
This commit is contained in:
@@ -53,8 +53,6 @@ class BatchRegistrar implements ImportBeanDefinitionRegistrar {
|
||||
|
||||
private static final String JOB_REPOSITORY = "jobRepository";
|
||||
|
||||
private static final String JOB_EXPLORER = "jobExplorer";
|
||||
|
||||
private static final String JOB_LAUNCHER = "jobLauncher";
|
||||
|
||||
private static final String JOB_REGISTRY = "jobRegistry";
|
||||
@@ -70,7 +68,6 @@ class BatchRegistrar implements ImportBeanDefinitionRegistrar {
|
||||
.get(EnableBatchProcessing.class)
|
||||
.synthesize();
|
||||
registerJobRepository(registry, batchAnnotation);
|
||||
registerJobExplorer(registry, batchAnnotation);
|
||||
registerJobLauncher(registry, batchAnnotation);
|
||||
registerJobRegistry(registry);
|
||||
registerJobRegistrySmartInitializingSingleton(registry);
|
||||
@@ -151,50 +148,6 @@ class BatchRegistrar implements ImportBeanDefinitionRegistrar {
|
||||
registry.registerBeanDefinition(JOB_REPOSITORY, beanDefinitionBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
private void registerJobExplorer(BeanDefinitionRegistry registry, EnableBatchProcessing batchAnnotation) {
|
||||
if (registry.containsBeanDefinition(JOB_EXPLORER)) {
|
||||
LOGGER.info("Bean jobExplorer already defined in the application context, skipping"
|
||||
+ " the registration of a jobExplorer");
|
||||
return;
|
||||
}
|
||||
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(JobExplorerFactoryBean.class);
|
||||
|
||||
// set mandatory properties
|
||||
String dataSourceRef = batchAnnotation.dataSourceRef();
|
||||
beanDefinitionBuilder.addPropertyReference("dataSource", dataSourceRef);
|
||||
|
||||
String transactionManagerRef = batchAnnotation.transactionManagerRef();
|
||||
beanDefinitionBuilder.addPropertyReference("transactionManager", transactionManagerRef);
|
||||
|
||||
// set optional properties
|
||||
String executionContextSerializerRef = batchAnnotation.executionContextSerializerRef();
|
||||
if (registry.containsBeanDefinition(executionContextSerializerRef)) {
|
||||
beanDefinitionBuilder.addPropertyReference("serializer", executionContextSerializerRef);
|
||||
}
|
||||
|
||||
String conversionServiceRef = batchAnnotation.conversionServiceRef();
|
||||
if (registry.containsBeanDefinition(conversionServiceRef)) {
|
||||
beanDefinitionBuilder.addPropertyReference("conversionService", conversionServiceRef);
|
||||
}
|
||||
|
||||
String jobKeyGeneratorRef = batchAnnotation.jobKeyGeneratorRef();
|
||||
if (registry.containsBeanDefinition(jobKeyGeneratorRef)) {
|
||||
beanDefinitionBuilder.addPropertyReference("jobKeyGenerator", jobKeyGeneratorRef);
|
||||
}
|
||||
|
||||
String charset = batchAnnotation.charset();
|
||||
if (charset != null) {
|
||||
beanDefinitionBuilder.addPropertyValue("charset", Charset.forName(charset));
|
||||
}
|
||||
|
||||
String tablePrefix = batchAnnotation.tablePrefix();
|
||||
if (tablePrefix != null) {
|
||||
beanDefinitionBuilder.addPropertyValue("tablePrefix", tablePrefix);
|
||||
}
|
||||
registry.registerBeanDefinition(JOB_EXPLORER, beanDefinitionBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
private void registerJobLauncher(BeanDefinitionRegistry registry, EnableBatchProcessing batchAnnotation) {
|
||||
if (registry.containsBeanDefinition(JOB_LAUNCHER)) {
|
||||
LOGGER.info("Bean jobLauncher already defined in the application context, skipping"
|
||||
|
||||
@@ -87,9 +87,6 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
* {@link TaskExecutorJobLauncher})</li>
|
||||
* <li>a {@link JobRegistry} (bean name "jobRegistry" of type
|
||||
* {@link org.springframework.batch.core.configuration.support.MapJobRegistry})</li>
|
||||
* <li>a {@link org.springframework.batch.core.explore.JobExplorer} (bean name
|
||||
* "jobExplorer" of type
|
||||
* {@link org.springframework.batch.core.explore.support.SimpleJobExplorer})</li>
|
||||
* <li>a {@link org.springframework.batch.core.launch.JobOperator} (bean name
|
||||
* "jobOperator" of type
|
||||
* {@link org.springframework.batch.core.launch.support.SimpleJobOperator})</li>
|
||||
|
||||
@@ -79,7 +79,6 @@ import org.springframework.transaction.annotation.Isolation;
|
||||
*
|
||||
* <ul>
|
||||
* <li>a {@link JobRepository} named "jobRepository"</li>
|
||||
* <li>a {@link JobExplorer} named "jobExplorer"</li>
|
||||
* <li>a {@link JobLauncher} named "jobLauncher"</li>
|
||||
* <li>a {@link JobRegistry} named "jobRegistry"</li>
|
||||
* <li>a {@link JobOperator} named "JobOperator"</li>
|
||||
@@ -169,26 +168,6 @@ public class DefaultBatchConfiguration implements ApplicationContextAware {
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JobExplorer jobExplorer() throws BatchConfigurationException {
|
||||
JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean();
|
||||
jobExplorerFactoryBean.setDataSource(getDataSource());
|
||||
jobExplorerFactoryBean.setTransactionManager(getTransactionManager());
|
||||
jobExplorerFactoryBean.setJdbcOperations(getJdbcOperations());
|
||||
jobExplorerFactoryBean.setJobKeyGenerator(getJobKeyGenerator());
|
||||
jobExplorerFactoryBean.setCharset(getCharset());
|
||||
jobExplorerFactoryBean.setTablePrefix(getTablePrefix());
|
||||
jobExplorerFactoryBean.setConversionService(getConversionService());
|
||||
jobExplorerFactoryBean.setSerializer(getExecutionContextSerializer());
|
||||
try {
|
||||
jobExplorerFactoryBean.afterPropertiesSet();
|
||||
return jobExplorerFactoryBean.getObject();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new BatchConfigurationException("Unable to configure the default job explorer", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JobRegistry jobRegistry() throws BatchConfigurationException {
|
||||
return new MapJobRegistry();
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.springframework.batch.core.configuration.support.JobRegistrySmartInit
|
||||
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
|
||||
import org.springframework.batch.core.converter.JobParametersConverter;
|
||||
import org.springframework.batch.core.converter.JsonJobParametersConverter;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
@@ -78,7 +77,6 @@ class BatchRegistrarTests {
|
||||
var context = new AnnotationConfigApplicationContext(JobConfigurationWithUserDefinedInfrastructureBeans.class);
|
||||
|
||||
Assertions.assertTrue(Mockito.mockingDetails(context.getBean(JobRepository.class)).isMock());
|
||||
Assertions.assertTrue(Mockito.mockingDetails(context.getBean(JobExplorer.class)).isMock());
|
||||
Assertions.assertTrue(Mockito.mockingDetails(context.getBean(JobLauncher.class)).isMock());
|
||||
Assertions.assertTrue(Mockito.mockingDetails(context.getBean(JobRegistry.class)).isMock());
|
||||
Assertions.assertTrue(Mockito.mockingDetails(context.getBean(JobOperator.class)).isMock());
|
||||
@@ -163,7 +161,6 @@ class BatchRegistrarTests {
|
||||
// when
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
JobRepository jobRepository = context.getBean(JobRepository.class);
|
||||
JobExplorer jobExplorer = context.getBean(JobExplorer.class);
|
||||
JobRegistry jobRegistry = context.getBean(JobRegistry.class);
|
||||
JobOperator jobOperator = context.getBean(JobOperator.class);
|
||||
JobRegistrySmartInitializingSingleton jobRegistrySmartInitializingSingleton = context
|
||||
@@ -172,7 +169,6 @@ class BatchRegistrarTests {
|
||||
// then
|
||||
Assertions.assertNotNull(jobLauncher);
|
||||
Assertions.assertNotNull(jobRepository);
|
||||
Assertions.assertNotNull(jobExplorer);
|
||||
Assertions.assertNotNull(jobRegistry);
|
||||
Assertions.assertNotNull(jobOperator);
|
||||
Assertions.assertNotNull(jobRegistrySmartInitializingSingleton);
|
||||
@@ -258,11 +254,6 @@ class BatchRegistrarTests {
|
||||
return Mockito.mock();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JobExplorer jobExplorer() {
|
||||
return Mockito.mock();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JobLauncher jobLauncher() {
|
||||
return Mockito.mock();
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.configuration.JobRegistry;
|
||||
import org.springframework.batch.core.configuration.xml.DummyJobRepository;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
@@ -98,7 +97,6 @@ class DefaultBatchConfigurationTests {
|
||||
// when
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
JobRepository jobRepository = context.getBean(JobRepository.class);
|
||||
JobExplorer jobExplorer = context.getBean(JobExplorer.class);
|
||||
JobRegistry jobRegistry = context.getBean(JobRegistry.class);
|
||||
JobOperator jobOperator = context.getBean(JobOperator.class);
|
||||
JobRegistrySmartInitializingSingleton jobRegistrySmartInitializingSingleton = context
|
||||
@@ -107,7 +105,6 @@ class DefaultBatchConfigurationTests {
|
||||
// then
|
||||
Assertions.assertNotNull(jobLauncher);
|
||||
Assertions.assertNotNull(jobRepository);
|
||||
Assertions.assertNotNull(jobExplorer);
|
||||
Assertions.assertNotNull(jobRegistry);
|
||||
Assertions.assertNotNull(jobOperator);
|
||||
Assertions.assertNotNull(jobRegistrySmartInitializingSingleton);
|
||||
|
||||
Reference in New Issue
Block a user