@PostConstruct注解的方法将会在程序启动的时候执行。
@PostConstruct注解好多人以为是Spring提供的。其实是Java自己的注解。
Java中该注解的说明:@PostConstruct该注解被用来修饰一个 非静态的void() 方法。被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器执行一次。PostConstruct在构造函数之后执行,init()方法之前执行。
@Component
public class MyUtils {
@PostConstruct
public void init(){
system.out.println("springboot 启动的时候我会执行一次")
}
}