You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a @JobParameter annotation for more convenient access to variables in JobParameters. #5563
I want to use the following code to access parameters in JobParameters.
@JobParameter can default to empty, in which case it uses the name of this local variable by default, or you can manually specify a name for value to find the corresponding variable.
Note: Perhaps this could also make it more convenient to add some extra functionality, such as specifying a converter separately.
@JobParameterprivateYearyear;
Current Behavior
Currently it is like this, and I find it rather rigid and not very convenient to use.
This is a great idea! Thank you for the feature request.
I will review #5564 and see if we can include this in 6.1
The same mechanism could cover #{jobExecutionContext['…']} and #{stepExecutionContext['…']} with similar annotations. Also, @JobParameters would need a separate design discussion about the injected type (Map vs JobParameters) and the name clash on snippets like private @JobParameters JobParameters.
@quaff yes, I think so, as mentioned in #5563 (comment). We need to think about the naming to avoid any confusion. In fact, @JobExecutionContext ExecutionContext ctx would suggest injecting the whole context, but the annotation (as I intended it) would inject one value in a similar fashion to @JobParameter. Probably @JobExecutionContextValue and @StepExecutionContextValue reads as "one value from that context". The term "Value" also pairs with the @Value they replace in @Value("#{JobExecutionContext['...']}").
However, while naming is hard and we can still manage to find a good non-confusing name, I am more concerned about the scope validity of those annotations: @JobScope beans only see jobExecutionContext, while @StepScope beans see both. Using the step variant on a job-scoped bean fails at runtime. I don't know whether the resolver can detect that early, because the descriptor may not expose the requesting bean's scope.
In any case, this should be discussed in a separate issue, likely for 6.2 or later.
10. @quaff yes, I think so, as mentioned in #5563 (comment). We need to think about the naming to avoid any confusion. In fact, @JobExecutionContext ExecutionContext ctx would suggest injecting the whole context, but the annotation (as I intended it) would inject one value in a similar fashion to @JobParameter. Probably @JobExecutionContextValue and @StepExecutionContextValue reads as "one value from that context". The term "Value" also pairs with the @Value they replace in @Value("#{JobExecutionContext['...']}").
However, while naming is hard and we can still manage to find a good non-confusing name, I am more concerned about the scope validity of those annotations: @JobScope beans only see jobExecutionContext, while @StepScope beans see both. Using the step variant on a job-scoped bean fails at runtime. I don't know whether the resolver can detect that early, because the descriptor may not expose the requesting bean's scope.
In any case, this should be discussed in a separate issue, likely for 6.2 or later.
I think we should rename JobParameterAutowireCandidateResolver and JobParameterBeanFactoryPostProcessor to more general name, since it will not only translate @JobParameter to @Value, what about BatchAnnotation*, WDYT? @fmbenhassine
@quaff Yes, if we decide to introduce those annotations (once the naming and scope are clarified in a separate issue), we can rename the BFPP to a more generic name.
if we decide to introduce those annotations (once the naming and scope are clarified in a separate issue), we can rename the BFPP to a more generic name.
Unlike JobParameterAutowireCandidateResolver is package-private, JobParameterBeanFactoryPostProcessor is public, it's better to rename before 6.1 release.
Yes, I am working on that to avoid a public API change later.
what about BatchAnnotation*, WDYT?
That's a broad name as we have other batch annotations that are not related to late binding. I'd go with LateBindingBeanFactoryPostProcessor and LateBindingAutowireCandidateResolver since it matches our docs. The reference page is "Late Binding of Job and Step Attributes". @JobParameter, @JobExecutionContextValue and @StepExecutionContextValue are all shorthands for the SpEL late-binding expressions documented there.
Also, the name describes the mechanism, not the list of annotations, so it doesn't need another rename later. Public BPPs here are named after what they do, like BatchObservabilityBeanPostProcessor and AutomaticJobRegistrarBeanPostProcessor. Spring's own resolvers read the same way, for example QualifierAnnotationAutowireCandidateResolver.
Activity
Introduce `@JobParameter` for convenient access to `JobParameters`
Introduce `@JobParameter` for convenient access to `JobParameters`
Introduce `@JobParameter` for convenient access to `JobParameters`
quaff commentedon Sep 30, 2026
@zhujianxintian Could you verify #5564 ?
zhujianxintian commentedon Sep 30, 2026
@quaff Thank you very much for your help and contribution!
fmbenhassine commentedon Oct 1, 2026
This is a great idea! Thank you for the feature request.
I will review #5564 and see if we can include this in 6.1
The same mechanism could cover
#{jobExecutionContext['…']}and#{stepExecutionContext['…']}with similar annotations. Also,@JobParameterswould need a separate design discussion about the injected type (MapvsJobParameters) and the name clash on snippets likeprivate @JobParameters JobParameters.But let's evaluate
@JobParameterfirst.Introduce `@JobParameter` for convenient access to `JobParameters`
quaff commentedon Oct 8, 2026
Is it worthy to introduce
@JobExecutionContextand@StepExecutionContext? I'd like to contribute it.fmbenhassine commentedon Oct 12, 2026
@quaff yes, I think so, as mentioned in #5563 (comment). We need to think about the naming to avoid any confusion. In fact,
@JobExecutionContext ExecutionContext ctxwould suggest injecting the whole context, but the annotation (as I intended it) would inject one value in a similar fashion to@JobParameter. Probably@JobExecutionContextValueand@StepExecutionContextValuereads as "one value from that context". The term "Value" also pairs with the@Valuethey replace in@Value("#{JobExecutionContext['...']}").However, while naming is hard and we can still manage to find a good non-confusing name, I am more concerned about the scope validity of those annotations:
@JobScopebeans only seejobExecutionContext, while@StepScopebeans see both. Using the step variant on a job-scoped bean fails at runtime. I don't know whether the resolver can detect that early, because the descriptor may not expose the requesting bean's scope.In any case, this should be discussed in a separate issue, likely for 6.2 or later.
Refine contribution #5564
Introduce `@JobParameter` for convenient access to `JobParameters`
quaff commentedon Oct 13, 2026
I think we should rename
JobParameterAutowireCandidateResolverandJobParameterBeanFactoryPostProcessorto more general name, since it will not only translate@JobParameterto@Value, what aboutBatchAnnotation*, WDYT? @fmbenhassinefmbenhassine commentedon Oct 13, 2026
@quaff Yes, if we decide to introduce those annotations (once the naming and scope are clarified in a separate issue), we can rename the BFPP to a more generic name.
quaff commentedon Oct 13, 2026
Unlike
JobParameterAutowireCandidateResolveris package-private,JobParameterBeanFactoryPostProcessoris public, it's better to rename before 6.1 release.fmbenhassine commentedon Oct 13, 2026
Yes, I am working on that to avoid a public API change later.
That's a broad name as we have other batch annotations that are not related to late binding. I'd go with
LateBindingBeanFactoryPostProcessorandLateBindingAutowireCandidateResolversince it matches our docs. The reference page is "Late Binding of Job and Step Attributes".@JobParameter,@JobExecutionContextValueand@StepExecutionContextValueare all shorthands for the SpEL late-binding expressions documented there.Also, the name describes the mechanism, not the list of annotations, so it doesn't need another rename later. Public BPPs here are named after what they do, like
BatchObservabilityBeanPostProcessorandAutomaticJobRegistrarBeanPostProcessor. Spring's own resolvers read the same way, for exampleQualifierAnnotationAutowireCandidateResolver.I will follow up with a commit for the rename.
Rename job parameter BFPP and resolver to a generic name