在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启动完成后才执行。
以上就是Springboot怎么在启动前执行代码的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号