@Test public void setApplicationContextRegistersAllScheduledJobBeansWithAutoRegistration() { var jobId = "JOB-MOCK"; var nonAutoRegisteredJob = new NonAutoRegisteredJob(); var jobMap = Map.of( "bean1", nonAutoRegisteredJob, "bean2", jobMock ); given(jobMock.getJobIdentifier()).willReturn(jobId); given(applicationContextMock.getBeansOfType(ScheduledJob.class)).willReturn(jobMap); scheduledJobExecutor.setApplicationContext(applicationContextMock); assertThat(scheduledJobExecutor.scheduledJobIdMap).containsExactly(Map.entry(jobMock, jobId)); }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { var scheduledJobs = applicationContext.getBeansOfType(ScheduledJob.class).values(); scheduledJobs.stream() .filter(this::shouldAutoRegister) .forEach(this::registerScheduledJob); }
ScheduledJobExecutor implements ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { var scheduledJobs = applicationContext.getBeansOfType(ScheduledJob.class).values(); scheduledJobs.stream() .filter(this::shouldAutoRegister) .forEach(this::registerScheduledJob); } }
ScheduledJobExecutor implements ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { var scheduledJobs = applicationContext.getBeansOfType(ScheduledJob.class).values(); scheduledJobs.stream() .filter(this::shouldAutoRegister) .forEach(this::registerScheduledJob); } @Autowired  ScheduledJobExecutor(ScheduledJobLogRepository jobLogRepo, Clock clock); }
ScheduledJobExecutor implements ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { var scheduledJobs = applicationContext.getBeansOfType(ScheduledJob.class).values(); scheduledJobs.stream() .filter(this::shouldAutoRegister) .forEach(this::registerScheduledJob); } @Autowired  ScheduledJobExecutor(ScheduledJobLogRepository jobLogRepo, Clock clock); @Scheduled( initialDelay = 0L, fixedDelay = 120_000L ) void executeJobs(); void registerScheduledJob(@NonNull ScheduledJob scheduledJob); @Override void setApplicationContext(ApplicationContext applicationContext); }
ScheduledJobExecutor implements ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { var scheduledJobs = applicationContext.getBeansOfType(ScheduledJob.class).values(); scheduledJobs.stream() .filter(this::shouldAutoRegister) .forEach(this::registerScheduledJob); } @Autowired  ScheduledJobExecutor(ScheduledJobLogRepository jobLogRepo, Clock clock); @Scheduled( initialDelay = 0L, fixedDelay = 120_000L ) void executeJobs(); void registerScheduledJob(@NonNull ScheduledJob scheduledJob); @Override void setApplicationContext(ApplicationContext applicationContext);  }