3

My Goal : Prevent batch Job from lunching while project startup.
I want to run a batch job from spring boot project once in every one hour using @scheduled annotation. However the job is starting as soon as I run the project....

spring.batch.job.enabled=false
@Scheduled( cron = "* * */1 * * *")
    public void jobScheduled(){
        logger.info("Job triggered");
        getAllFileNames().stream().forEach( fileName-> {

            jobRunner.runFlatFileBatchJob(fileName);

        });
    }

I have declared my class like below


@Configuration
@EnableScheduling
public class JobScheduler {

@Autowired
    public JobScheduler(JobRunner jobRunner){
        logger.info("job scheduler created... ");
        this.jobRunner = jobRunner;
    }

The Job is starting as soon as Run the application. I want it to wait till the project loads completely and other integration objects prepare themselves.

Thanks in advance.
Santrupta Dash

Santrupta Dash
  • 269
  • 2
  • 15
  • 1
    That probably means that the property is not taken into account. Can you share how you are declaring it? Is it in a properties file or in a yaml file (is this case it the file correctly indented?)? Please share a [minimal example](https://stackoverflow.com/help/minimal-reproducible-example) that reproduces the issue to be able to help you efficiently. – Mahmoud Ben Hassine Aug 20 '22 at 06:15
  • There was a @Bean annotation with the scheduled method. After removing the Bean annotation it worked fine. And the batch did not load during the start-up. Thanks. – Santrupta Dash Aug 20 '22 at 15:46

0 Answers0