需要实现 ApplicationListener<ContextRefreshedEvent>
@Component public class CrawlerInitialize implements ApplicationListener<ContextRefreshedEvent> { @Override public void onApplicationEvent(ContextRefreshedEvent event) { CrawlerWebsiteService crawlerWebsiteService = SpringContextHolder.getBean(CrawlerWebsiteService.class); crawlerWebsiteService.initCrawlerStatus(StatusEnum.STOP.getValue()); } }