需要实现 ApplicationListener<ContextRefreshedEvent>
@Componentpublic class CrawlerInitialize implements ApplicationListener{ @Override public void onApplicationEvent(ContextRefreshedEvent event) { CrawlerWebsiteService crawlerWebsiteService = SpringContextHolder.getBean(CrawlerWebsiteService.class); crawlerWebsiteService.initCrawlerStatus(StatusEnum.STOP.getValue()); }}
@PostConstruct :可以使用@PostConstruct注解一个方法来完成初始化,@PostConstruct注解的方法将会在依赖注入完成后被自动调用