在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启动完成后才执行。










