Springboot怎么在启动前执行代码
作者:WeekendFlower
时间:2023-05-11
浏览:3
在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启动完成后才执行。
作者最新文章
再漫画官网首页入口及在线观看方法
2026-11-05 09:42
ArchiveofOurOwn官网链接及同人文学阅读入口
2026-10-30 10:21
多张照片怎么合成PDF文件?三种图片转PDF工具怎么选?
2026-10-29 15:06
音述AI作品如何复制分享链接发给好友
2026-10-27 12:00
冰点还原怎么打开 程序启动步骤
2026-10-23 13:35
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多
























