Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Spring batch tasklet execute method not calling

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Iam trying spring batch version 4. Iam facing one problem with tasklet 's execute is never called.

here is my code:


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class Main {

   public static void main(String args[]) {
       System.out.println(3);
       SpringApplication.run(Main.class, args);
       System.out.println(4);
   }
}

/********Tasklet*****/


import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;

public class DemoTasklet implements Tasklet, StepExecutionListener {

   public DemoTasklet() {
       System.out.println("demo tasklet constructor");
   }

   @Override
   public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
       System.out.println("hello");
       return RepeatStatus.FINISHED;
   }

   @Override
   public void beforeStep(StepExecution stepExecution) {
       System.out.println("before");
   }

   @Override
   public ExitStatus afterStep(StepExecution stepExecution) {
       System.out.println("after");
       return stepExecution.getExitStatus();
   }
}

/*******Main code*****/

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration
@EnableBatchProcessing
public class BatchConfiguration {

   @Autowired
   private JobBuilderFactory jobBuilderFactory;

   @Autowired
   private StepBuilderFactory stepBuilderFactory;

   @Bean
   public Step step1() {
       return stepBuilderFactory.get("step1")
               .tasklet(new DemoTasklet())
               .build();
   }

   @Bean
   public Job job() throws Exception {
       return jobBuilderFactory.get("job")
               .incrementer(new RunIdIncrementer())
               .flow(step1())
               .end()
               .build();
   }
}



Please help. Its calling only constructor. not execute method.



Thanks in advance
 
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please elaborate your problem.
 
vinoth sathi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Joe wrote:Please elaborate your problem.




Hi,

Iam trying to do some login in execute method(public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) ). But its not calling to execute method. its only calling DemoTasklet constructor.

what is the problem?
 
vinoth sathi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry. typo error. Not login . i mean logic
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened if you remove these code since you have created a class named DemoTasklet ?
 
vinoth sathi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Joe wrote:What happened if you remove these code since you have created a class named DemoTasklet ?



Hi,  Thanks now working.
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vinoth sathi wrote:Hi,  Thanks now working.

Great
 
We noticed he had no friends. So we gave him this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic