Make JobOperator extend JobLauncher

Related to #4832
This commit is contained in:
Mahmoud Ben Hassine
2025-05-07 22:03:03 +02:00
parent adffc588b6
commit fc4a66516a
19 changed files with 105 additions and 179 deletions

View File

@@ -6,11 +6,6 @@
<import resource="classpath:data-source-context.xml" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.TaskExecutorJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean class="org.springframework.batch.core.configuration.support.JobRegistrySmartInitializingSingleton">
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
@@ -51,12 +46,8 @@
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
<property name="jobRepository" ref="jobRepository" />
<property name="jobRegistry" ref="jobRegistry" />
<property name="jobLauncher">
<bean parent="jobLauncher">
<property name="taskExecutor">
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
</property>
</bean>
<property name="taskExecutor">
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
</property>
</bean>

View File

@@ -1,18 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- The tasklet used in this job will run in an infinite loop. This is useful for testing graceful shutdown from
multiple environments. -->
<import resource="classpath:data-source-context.xml" />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.TaskExecutorJobLauncher">
<property name="jobRepository" ref="jobRepository" />
<bean class="org.springframework.batch.core.configuration.support.JobRegistrySmartInitializingSingleton">
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JdbcJobRepositoryFactoryBean"
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager"/>
<bean id="jobOperator"
class="org.springframework.batch.core.launch.support.SimpleJobOperator"
p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry">
<property name="taskExecutor">
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
</property>
</bean>
<bean id="jobRegistry"
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
<bean class="org.springframework.batch.test.JobLauncherTestUtils"/>
<bean class="org.springframework.batch.test.context.BatchTestContextBeanPostProcessor"/>
<!-- The tasklet used in this job will run in an infinite loop. This is useful for testing graceful shutdown from
multiple environments. -->
<bean id="simpleJob" class="org.springframework.batch.core.job.SimpleJob" abstract="true">
<property name="jobRepository" ref="jobRepository" />
<property name="restartable" value="true" />

View File

@@ -6,14 +6,10 @@
<import resource="classpath:data-source-context.xml" />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.TaskExecutorJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JdbcJobRepositoryFactoryBean"
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" />
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator" p:jobLauncher-ref="jobLauncher"
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator"
p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry" />
<bean id="jobExplorer" class="org.springframework.batch.core.repository.explore.support.JobExplorerFactoryBean"

View File

@@ -6,11 +6,6 @@
<import resource="data-source-context.xml" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.TaskExecutorJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean class="org.springframework.batch.core.configuration.support.JobRegistrySmartInitializingSingleton">
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
@@ -21,11 +16,7 @@
<bean id="jobOperator"
class="org.springframework.batch.core.launch.support.SimpleJobOperator"
p:jobLauncher-ref="jobLauncher" p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry" />
<bean id="jobExplorer"
class="org.springframework.batch.core.repository.explore.support.JobExplorerFactoryBean"
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager"/>
p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry" />
<bean id="jobRegistry"
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,8 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @author Mahmoud Ben Hassine
*
*/
@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml",
"/org/springframework/batch/samples/restart/stop/stopRestartSample.xml" })
@SpringJUnitConfig(locations = { "/org/springframework/batch/samples/restart/stop/stopRestartSample.xml" })
class GracefulShutdownFunctionalTests {
/** Logger */

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2023 the original author or authors.
* Copyright 2008-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,8 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml",
"/org/springframework/batch/samples/restart/stop/stopRestartSample.xml" })
@SpringJUnitConfig(locations = { "/org/springframework/batch/samples/restart/stop/stopRestartSample.xml" })
class JobOperatorFunctionalTests {
private static final Log LOG = LogFactory.getLog(JobOperatorFunctionalTests.class);
@@ -50,16 +49,6 @@ class JobOperatorFunctionalTests {
@Autowired
private Job job;
@Autowired
private JobRegistry jobRegistry;
@BeforeEach
void setUp() throws Exception {
if (!jobRegistry.getJobNames().contains(job.getName())) {
jobRegistry.register(new ReferenceJobFactory(job));
}
}
@Test
void testStartStopResumeJob() throws Exception {
String params = "jobOperatorTestParam=7,java.lang.Long,true";