下面列出了怎么用org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor的API类实例代码及写法,或者点击链接到github查看源代码。
@Autowired
public PipelineController(
ExecutionLauncher executionLauncher,
ExecutionRepository executionRepository,
ObjectMapper kayentaObjectMapper,
ConfigurableApplicationContext context,
HealthIndicatorRegistry healthIndicators,
HealthAggregator healthAggregator,
ScheduledAnnotationBeanPostProcessor postProcessor) {
this.executionLauncher = executionLauncher;
this.executionRepository = executionRepository;
this.kayentaObjectMapper = kayentaObjectMapper;
this.context = context;
this.healthIndicator = new CompositeHealthIndicator(healthAggregator, healthIndicators);
this.postProcessor = postProcessor;
}
@Test
public void shouldRegisterSchedulerPostProcessor() {
// when
ScheduledAnnotationBeanPostProcessor bean =
applicationContext.getBean(ScheduledAnnotationBeanPostProcessor.class);
// then
assertNotNull(bean);
}
@Test
public void stopJobSchedulerWhenSchedulerDestroyed() throws Exception {
ScheduledAnnotationBeanPostProcessor bean = context.getBean(ScheduledAnnotationBeanPostProcessor.class);
SpringBatchScheduler schedulerBean = context.getBean(SpringBatchScheduler.class);
await().untilAsserted(() -> Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
.get()));
bean.postProcessBeforeDestruction(schedulerBean, "SpringBatchScheduler");
await().atLeast(3, SECONDS);
Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
.get());
}
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Autowired
public void setTaskScheduler(ScheduledAnnotationBeanPostProcessor taskScheduler) {
this.taskScheduler = taskScheduler;
}