Skip to content

Provide a @JobParameter annotation for more convenient access to variables in JobParameters. #5563

Closed

Description

@zhujianxintian

Expected Behavior

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.

@JobParameter
private Year year;

Current Behavior

Currently it is like this, and I find it rather rigid and not very convenient to use.

@Value("#{jobParameters['year']}")
private Year year;

Activity

  1. added 3 commits that reference this issue on Sep 29, 2026
    7ffa65c
    e091201
    865158c
  2. quaff commented on Sep 30, 2026

    @quaff
    Contributor

    @zhujianxintian Could you verify #5564 ?

  3. zhujianxintian commented on Sep 30, 2026

    @zhujianxintian
    Author

    @quaff Thank you very much for your help and contribution!

  4. fmbenhassine commented on Oct 1, 2026

    @fmbenhassine
    Contributor

    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.

    But let's evaluate @JobParameter first.

  5. added
    status: waiting-for-reporter
    and removed
    status: waiting-for-triage
    status: waiting-for-reporter
    on Oct 1, 2026
  6. added a commit that references this issue on Oct 8, 2026
    ec21879
  7. quaff commented on Oct 8, 2026

    @quaff
    Contributor

    Is it worthy to introduce @JobExecutionContext and @StepExecutionContext? I'd like to contribute it.

  8. fmbenhassine commented on Oct 12, 2026

    @fmbenhassine
    Contributor

    @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.

  9. added a commit that references this issue on Oct 12, 2026
  10. added a commit that references this issue on Oct 12, 2026
    a7d6678
  11. quaff commented on Oct 13, 2026

    @quaff
    Contributor

    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

  12. added this to the 6.1.0-RC1 milestone on Oct 13, 2026
  13. fmbenhassine commented on Oct 13, 2026

    @fmbenhassine
    Contributor

    @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.

  14. quaff commented on Oct 13, 2026

    @quaff
    Contributor

    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.

  15. fmbenhassine commented on Oct 13, 2026

    @fmbenhassine
    Contributor

    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.

    I will follow up with a commit for the rename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions