In the vernacular :
@PostConstruct
从Java EE5规范开始,Servlet中增加了两个影响Servlet生命周期的注解,
@PostConstruct和@PreDestroy,这两个注解被用来修饰一个非静态的void()方法。写法有如下两种方式:
@PostConstruct
public void someMethod(){
}
or
public @PostConstruct void someMethod(){
}
The method decorated by @PostConstruct will run when the server loads the Servlet, and will only be executed once by the server. PostConstruct is executed after the constructor and before the init() method.
Annotate a method with @PostConstruct to complete initialization, and the method annotated with @PostConstruct will be automatically called after dependency injection is completed.
tips:
The sequence of Constructor, @Autowired, and @PostConstruct in spring
Constructor >> @Autowired >> @PostConstruct