partitioned-batch-job raises org.springframework.cloud.task.listener.TaskExecutionException when Partitioner is @StepScope
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with the partitioned-batch-job sample and the @StepScope partitionHandler and partitionedJob methods shown in the issue. Reproduce the taskLifecycleListener failure and trace how the scoped partitionHandler is referenced when the job is created. Done means the sample supports passing the step name for multiple steps without the step-scope exception.
Written by the indexing model from the issue text.
Description
Hello,
I modified the partitioned-batch-job sample such that the PartitonHandler class reads as follows:
@Bean
@StepScope
public DeployerPartitionHandler partitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer, TaskRepository taskRepository, String stepName)
{
Resource resource = this.resourceLoader.getResource("...");
DeployerPartitionHandler partitionHandler = new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName);
List<String> commandLineArgs = new ArrayList<>(3);
commandLineArgs.add("--spring.profiles.active=worker");
commandLineArgs.add("--spring.cloud.task.initialize-enabled=false");
commandLineArgs.add("--spring.batch.initializer.enabled=false");
partitionHandler.setCommandLineArgsProvider(new PassThroughCommandLineArgsProvider(commandLineArgs));
partitionHandler.setEnvironmentVariablesProvider(new SimpleEnvironmentVariablesProvider(this.environment));
partitionHandler.setMaxWorkers(2);
partitionHandler.setApplicationName("PartitionedBatchJobTask");
return partitionHandler;
}
And I also modified the method partitonJob as follows:
@Bean
@Profile("!worker")
public Job partitionedJob(/*PartitionHandler partitionHandler*/)
{
Random random = new Random();
return this.jobBuilderFactory.get("partitionedJob" + random.nextInt())
.start(step1(partitionHandler(taskLauncher, jobExplorer, taskRepository, "workerStep")))
.build();
}
This is in order to use multiple steps and, hence, to be able to pass the step name as an input argument of the partitinHandler() method.
Running the job raises the following exception:
org.springframework.context.ApplicationContextException: Failed to start bean 'taskLifecycleListener'; nested exception is
org.springframework.cloud.task.listener.TaskExecutionException: Failed to process @BeforeTask or @AfterTask annotation
because: Error creating bean with name 'scopedTarget.partitionHandler': Scope 'step' is not active for the current thread;
consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is
java.lang.IllegalStateException: No context holder available for step scope
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring- context-5.3.8.jar:5.3.8]
...
I have found many similar cases on stackoverflow but no working solutions. Please advise.
Many thanks in advance.
- Dominant language
- Java
- Stars
- 446
- Forks
- 310
- Avg merge
- 18h 18m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spring-cloud/spring-cloud-task
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
spring-cloud/spring-cloud-task#954 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
spring-cloud/spring-cloud-task#953 · 1 comment ·
-
status: waiting-on-feedback
Difficulty 4/5 3-5 days Newbie friendliness 25/100
spring-cloud/spring-cloud-task#952 · 2 comments ·
-
App is failing with 'taskLifecycleListener' bean initialization errors post Spring Boot 3.x upgrade Openstatus: waiting-on-feedback
Difficulty 5/5 Over a week Newbie friendliness 15/100
spring-cloud/spring-cloud-task#950 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
All issues in spring-cloud/spring-cloud-task
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100