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