@PostConstruct注解

Posted Marlo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了@PostConstruct注解相关的知识,希望对你有一定的参考价值。

@PostConstruct基本:
@PostConstruct注解不是Spring提供的;是Java自己提供的注解。

Java中该注解的说明:
1.@PostConstruct该注解被用来修饰一个非静态的void()方法。
2.被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器执行一次。
3.PostConstruct在构造函数之后执行,init()方法之前执行。

通常我们会是在Spring框架中使用到@PostConstruct注解 该注解的方法在整个Bean初始化中的执行顺序:

Constructor(构造方法) -> @Autowired(依赖注入) -> @PostConstruct(注释的方法)

应用:在静态方法中调用依赖注入的Bean中的方法。

以上是关于@PostConstruct注解的主要内容,如果未能解决你的问题,请参考以下文章

@PostConstruct注解

@PostConstruct注解介绍

@PostConstruct 注解

@PostConstruct和@PreConstruct注解

@PostConstruct注解小结

@PostConstruct 注解