/*** The PostConstruct annotation is used on a method that needs to be executed* after dependency injection is done to perform any initialization. This* method MUST be invoked before the class is put into service. This* annotation MUST be supported on all classes that support dependency* injection. The method annotated with PostConstruct MUST be invoked even* if the class does not request any resources to be injected. Only one* method can be annotated with this annotation. The method on which the* PostConstruct annotation is applied MUST fulfill all of the following* criteria:* <p>* <ul>* <li>The method MUST NOT have any parameters except in the case of* interceptors in which case it takes an InvocationContext object as* defined by the Interceptors specification.</li>* <li>The method defined on an interceptor class MUST HAVE one of the* following signatures:* <p>* void <METHOD>(InvocationContext)* <p>* Object <METHOD>(InvocationContext) throws Exception* <p>* <i>Note: A PostConstruct interceptor method must not throw application* exceptions, but it may be declared to throw checked exceptions including* the java.lang.Exception if the same interceptor method interposes on* business or timeout methods in addition to lifecycle events. If a* PostConstruct interceptor method returns a value, it is ignored by* the container.</i>* </li>* <li>The method defined on a non-interceptor class MUST HAVE the* following signature:* <p>* void <METHOD>()* </li>* <li>The method on which PostConstruct is applied MAY be public, protected,* package private or private.</li>* <li>The method MUST NOT be static except for the application client.</li>* <li>The method MAY be final.</li>* <li>If the method throws an unchecked exception the class MUST NOT be put into* service except in the case of EJBs where the EJB can handle exceptions and* even recover from them.</li></ul>* @since Common Annotations 1.0* @see javax.annotation.PreDestroy* @see javax.annotation.Resource*//*** PostConstruct注解用在需要执行的方法上* 在完成依赖注入以执行任何初始化之后。这* 方法必须在类投入使用之前调用。这* 所有支持依赖的类都必须支持注解* 注射。使用 PostConstruct 注释的方法必须被调用,甚至* 如果类不请求注入任何资源。只有一个* 方法可以用这个注解来注解。所采用的方法* 应用 PostConstruct 注释必须满足以下所有条件* 标准:* <p>* <ul>* <li>方法不能有任何参数,除非是* 拦截器,在这种情况下,它需要一个 InvocationContext 对象作为* 由拦截器规范定义。</li>* <li>在拦截器类上定义的方法必须具有* 以下签名:* <p>* void <METHOD>(InvocationContext)* <p>* 对象 <METHOD>(InvocationContext) 抛出异常* <p>* <i>注意:PostConstruct 拦截器方法不能抛出应用程序* 异常,但可以声明抛出检查异常,包括* java.lang.Exception 如果相同的拦截器方法插入* 除了生命周期事件之外的业务或超时方法。如果一个* PostConstruct 拦截器方法返回一个值,它被忽略* 容器。</i>* </li>* <li>在非拦截器类上定义的方法必须具有* 以下签名:* <p>* 无效 <方法>()* </li>* <li>应用 PostConstruct 的方法可以是公共的、受保护的、* 包私有或私有。</li>* <li>除了应用程序客户端之外,该方法不得是静态的。</li>* <li>方法可能是最终的。</li>* <li>如果方法抛出未经检查的异常,则不得将类放入* 服务,除了 EJB 可以处理异常的 EJB 和* 甚至从他们身上恢复过来。</li></ul>* @since 通用注解 1.0* @see javax.annotation.PreDestroy* @see javax.annotation.Resource*/@Documented@Retention (RUNTIME)@Target(METHOD)public @interface PostConstruct {}
当一个class被注解为一个Bean,那么class上被@PostConstruct注解的方法将会在程序启动的时候执行。
是Java自己的注解
该注解的方法在整个Bean初始化中的执行顺序:Constructor(构造方法) -> @Autowired(依赖注入) -> @PostConstruct(注释的方法)
