Spring项目初始化

须要实现 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注解的方法将会在依赖注入完成后被自动调用
相关文章
相关标签/搜索