This week's book giveaway is in the iOS forum.
We're giving away four copies of Classic Computer Science Problems in Swift and have David Kopec on-line!
See this thread for details.
Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Spring batch tasklet execute method not calling  RSS feed

 
Greenhorn
Posts: 16
  • 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: 539
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please elaborate your problem.
 
vinoth sathi
Greenhorn
Posts: 16
  • 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: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry. typo error. Not login . i mean logic
 
John Joe
Ranch Hand
Posts: 539
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: 16
  • 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: 539
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vinoth sathi wrote:Hi,  Thanks now working.

Great
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!