摘要: spring boot 启动加载 CommandLineRunner 在项目中,经常有这样的需求,我们需要在项目启动完立即初始化一些数据(比如缓存等),以便后面调用使用。spring boot可以通过CommandLineRunner接口实现启动加载功能。 新建一个Java文件,类需要用Compon 阅读全文
posted @ 2021-08-11 22:09 Bonnie_ξ 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 往往我们在项目启动时需要加载某个方法的时候,可以使用@Component+@PostConstruct方法将一个方法完成初始化操作,@PostConstruct注解的方法会将在依赖注入完成之后被自动调用。该注解在整个Bean初始化中执行的顺序: @Constructor(构造方法)->@Autowi 阅读全文
posted @ 2021-08-11 21:52 Bonnie_ξ 阅读(592) 评论(0) 推荐(0) 编辑
摘要: 先看CommandLineRunner接口的API: import org.springframework.core.annotation.Order; public interface CommandLineRunner { /** * Callback used to run the bean. 阅读全文
posted @ 2021-08-11 16:06 Bonnie_ξ 阅读(159) 评论(0) 推荐(0) 编辑