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
- I found no sign in
JobLauncherApplicationRunner
that this class is a spring managed bean, then why/how this class uses@Autowired
? - This class implements
ApplicationRunner
interface, againSpring boot
finds all beans, and after application context refreshed, it will executes therun
method of this interface for those beans that implemented this interface. how spring registersJobLauncherApplicationRunner
?
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
.