Springboot怎么在启动前执行代码
作者:WeekendFlower
时间:2023-05-11
浏览:2
在Springboot自动实例化类前,我们需要准备一些数据在类型实例化的时候使用。经过测试,在启动类添加注解@PostConstruct有效。@SpringBootApplicationpublicclassMyApplication{publicstaticvoidmain(String[]args){SpringApplication.run(MyApplication.class,args);}//springboot正式启动前@PostConstructpublicvoidpostConstruc
本文目录
在Springboot自动实例化类前,我们需要准备一些数据在类型实例化的时候使用。 经过测试,在启动类添加注解@PostConstruct有效。
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
// springboot正式启动前
@PostConstruct
public void postConstruct(){
System.out.println("执行Springboot正式启动前的代码")
}
}实现Spring的ApplicationRunner与CommandLineRunner接口的办法,都只在Springboot启动完成后才执行。
作者最新文章
GoldWave快捷键及常用功能操作教程
2026-10-14 14:48
SQL条件逻辑转换:CASE WHEN语句在数据分类中的应用
2026-10-13 16:41
漫蛙官网入口最新版本下载
2026-10-13 13:19
漫蛙动漫最新版本app下载安装
2026-10-13 13:18
漫蛙APP下载安装免费版
2026-10-13 13:18
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多

































