@PostConstruct是干什么的

大白话
@PostConstruct

	从Java EE5规范开始,Servlet中增加了两个影响Servlet生命周期的注解,
	@PostConstruct和@PreDestroy,这两个注解被用来修饰一个非静态的void()方法。写法有如下两种方式:
@PostConstruct
public void someMethod(){
    
    }

或者

public @PostConstruct void someMethod(){
    
    }

被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器执行一次。PostConstruct在构造函数之后执行,init()方法之前执行。

使用@PostConstruct注解一个方法来完成初始化,@PostConstruct注解的方法将会在依赖注入完成后被自动调用。

tips:
spring中Constructor、@Autowired、@PostConstruct的顺序
Constructor >> @Autowired >> @PostConstruct

猜你喜欢

转载自blog.csdn.net/plqaxx/article/details/108704556