INDEX
Spring 启动相关的钩子
- before - main
- @PostConstruct
- ApplicationListener<ApplicationStartedEvent>
- ApplicationRunner.run()
- commandLineRunner.run()
- ApplicationListener<ApplicationReadyEvent>
- after - main
实际使用中,只推荐使用
- @PostConstruct
广泛用于几乎所有 SpringBean 的初始化,推荐所有即时生效的对象在这里完成自定义构建,比如具有状态的容器,或需要进行初始化并即时生效的对象 - ApplicationRunner.run()
可以用于允许延时加载的工作