Skip to content
Advertisement

explain how JobLauncherApplicationRunner class works?

I was reading the source code of JobLauncherApplicationRunner. according to my understanding when we use Spring boot + Spring batch, this class is used to find all the jobs in the application context and use SimpleJobLauncher to execute jobs in startup. I found some cases that contradicts my previous knowledge and if you help me out I will be grateful

  1. I found no sign in JobLauncherApplicationRunner that this class is a spring managed bean, then why/how this class uses @Autowired?
  2. This class implements ApplicationRunner interface, again Spring boot finds all beans, and after application context refreshed, it will executes the run method of this interface for those beans that implemented this interface. how spring registers JobLauncherApplicationRunner?

Advertisement

Answer

It is created as part of the auto configuration of Spring Batch. This auto configuration can be found in the BatchAutoConfiguration class.

Here it will, conditionally, create an instance of the JobLauncherApplicationRunner.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement