springboot项目启动执行特定方法
2019-01-23 14:32
666 查看
参考博客:
https://www.geek-share.com/detail/2715447781.html
实现ApplicationRunner接口即可
直接上代码:
/** * @author : lichenfei * @date : 2019年1月23日 * @time : 下午2:12:20 * */ package com.lcf.app.start; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; /** * @author : lichenfei * @date : 2019年1月23日 * @time : 下午2:12:20 * */ @Component // bean组件注解 @Order(1) // 指定执行顺序 public class StartOne implements ApplicationRunner { /* * 项目启动时执行的方法 */ public void run(ApplicationArguments args) throws Exception { System.err.println("StartOne方法开始执行..."); } }
/** * @author : lichenfei * @date : 2019年1月23日 * @time : 下午2:12:20 * */ package com.lcf.app.start; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; /** * @author : lichenfei * @date : 2019年1月23日 * @time : 下午2:12:20 * */ @Component // bean组件注解 @Order(2) // 指定执行顺序 public class StartTwo implements ApplicationRunner { /* * 项目启动时执行的方法 */ public void run(ApplicationArguments args) throws Exception { System.err.println("StartTwo方法开始执行..."); } }
运行结果:
相关文章推荐
- Spring Boot学习--项目启动时执行特定方法(对于quartz 任务调度一样也是可行)
- Spring Boot学习--项目启动时执行特定方法
- springboot 学习之路 9 (项目启动后就执行特定方法)
- spring项目启动完成后,自动执行一次某个特定方法。
- spring boot在启动项目之后执行的实现方法
- springboot 启动后执行特定的方法
- springboot项目启动后第一次执行controller方法时进入很慢
- 在springboot中,如何做到当项目启动的时候去执行这个逻辑
- Spring Boot解决项目启动时初始化资源的方法
- SpringBoot项目不占用端口启动的方法
- Spring Boot学习--项目启动时执行特定方法
- Spring项目启动时执行初始化方法
- Centos下SpringBoot项目启动与停止脚本的方法
- springboot项目执行controller方法时进入慢的问题
- 项目启动 spring初始化bean之后执行指定方法
- Mac idea 启动SpringBoot 项目慢解决方法
- 详解Spring Boot 项目启动时执行特定方法
- springBoot项目启动类启动无法访问的解决方法
- Intellij IDEA实现SpringBoot项目多端口启动的两种方法
- Spring boot启动之后执行方法 CommandLineRunner