Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9018275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:29:02+00:00 2026-06-16T04:29:02+00:00

I have a Spring Batch job which takes parameters, and the parameters are usually

  • 0

I have a Spring Batch job which takes parameters, and the parameters are usually the same every time the job is run. By default, Spring Batch doesn’t let you re-use the same parameters like that… so I created a simple incrementer and added it to my job like this:

http://numberformat.wordpress.com/2010/02/07/multiple-batch-runs-with-spring-batch/

When using the standard CommandLineJobRunner to run my job, I have to pass the -next parameter in order for my incrementer to be used.

However, when I run an end-to-end job test from within a JUnit class, using JobLauncherTestUtils.launchJob( JobParameters )… I can’t find a way to declare that my incrementer should be used. The job is just quietly skipped, presumably because it has already been run with those parameters (see note below).

The JobParameters class is meant to hold a collection of name-value pairs… but the -next parameter is different. It starts with a dash, and has no corresponding value. I tried various experiments, but trying to add something to the JobParameters collection doesn’t seem to be the ticket.

Does anyone know the JUnit equivalent to passing -next to CommandLineJobRunner?

NOTE: I presume that the the issue is my incrementer being ignored, because:

  1. The job works the first time, and it works if I wipe out the job repository database. It only fails on retries.
  2. The job works fine, retries and all, when I hardcode the variables and remove the parameters altogether.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:29:04+00:00Added an answer on June 16, 2026 at 4:29 am

    JobLauncherTestUtils class contains a getUniqueJobParameters method which serves exactly the same need.

    /**
    * @return a new JobParameters object containing only a parameter for the
    * current timestamp, to ensure that the job instance will be unique.
    */
    public JobParameters getUniqueJobParameters() {Map<String, JobParameter> 
    parameters = new HashMap<String, JobParameter>();
    parameters.put("random", new JobParameter((long) (Math.random() * JOB_PARAMETER_MAXIMUM)));
    return new JobParameters(parameters);
    }
    

    Sample usage would be,

    JobParameters params = new JobParametersBuilder (jobLauncherTestUtils.getUniqueJobParameters()).toJobParameters();
         //extra parameters to be added
    JobExecution jobExecution = jobLauncherTestUtils.launchJob(params);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one spring batch application which can be run from command line. The
i have a spring batch job which needs to be scheduled at specific hour
I have defined a Spring Batch job which runs once just fine. However it
I have a Spring Batch process which has following kind of code. <step id=step1
I have a Spring Batch job consisting of two steps (so far). The first
I have a Spring Roo + Hibernate project which takes a JTS well-known text
I have a Spring Batch application, which I start with the CommandLineJobRunner . But
What I want to achieve: I have set up a Spring Batch Job containing
I have a spring batch program which reads from a database and writes to
I have a spring batch program which reads from a file and writes to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.