[JAVA] @BeforeStep does not work in Tasklet of spring-batch

Even if I add a method that adds `@ BeforeStep``` to `Tasklet``` as shown below in spring-batch, it does not work as intended.

@Component
public class MyTasklet implements Tasklet {
    
    @BeforeStep
    void beforeStep(StepExecution stepExecution) {
        System.out.println("asdfasdf");
    }

Cause

Probably because there is no automatic listener registration in Tasklet.

If you implement a listener such as StepExecutionListener in the implementation class such as ItemReader, that listener will also be automatically registered (at least for running spring-batch with spring-boot). See Spring-batch is automatically registered when listener is implemented by reader.

As mentioned above, it seems that ItemReader has automatic listener registration, but `` `Tasklet``` does not. I'm just guessing because I haven't followed the source or documentation properly.

solution

https://stackoverflow.com/questions/29935824/beforestep-annotated-method-not-being-called

Use the execute </ code> method argument `chunkContext``` or implement `StepExecutionListener```.

Recommended Posts

@BeforeStep does not work in Tasklet of spring-batch
When @Transactional of Spring Boot does not work
Sidekiq-limit_fetch does not work
Hivernate Validator does not work in WAS Liberty environment
About the matter that: nth-child (-n + m) does not work as intended in the selector of jsoup
eclipse tab width change does not work.
JavaScript (vanilla) does not respond in Rails.
MySQL container does not start in Docker
.sql file does not run in docker-compose
When the form such as Select of Materialize does not work properly
Code written in Java-TeraPad starting from beginner does not work due to error
Does the escape sequence (\) not work? (for Mac)
"Do not show again" check does not work in the warning dialog when starting applet
Localhost3000 does not start up in Docker / Rails development.
Note: Memory Analyzer does not work on Mac OS
Correspondence when Ruby version does not switch in rbenv
Does .dockerignore not work? It's written differently from .gitignore!
[Ruby on Rails] credential does not work in production environment even though I saved production.key