1 /*
   2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.annotation;
  27 
  28 import java.lang.annotation.*;
  29 import static java.lang.annotation.ElementType.*;
  30 import static java.lang.annotation.RetentionPolicy.*;
  31 
  32 /**
  33  * The <code>PostConstruct</code> annotation is used on a method that
  34  * needs to be executed after dependency injection is done to perform
  35  * any initialization. This  method must be invoked before the class
  36  * is put into service. This annotation must be supported on all classes
  37  * that support dependency injection. The method annotated with
  38  * <code>PostConstruct</code> must be invoked even if the class does
  39  * not request any resources to be injected. Only one
  40  * method in a given class can be annotated with this annotation.
  41  * The method on which the <code>PostConstruct</code> annotation is
  42  * applied must fulfill all of the following criteria:
  43  * <ul>
  44  * <li>The method must not have any parameters except in the case of
  45  * interceptors in which case it takes an <code>InvocationContext</code>
  46  * object as defined by the Interceptors specification.</li>
  47  * <li>The method defined on an interceptor class or superclass of an
  48  * interceptor class must have one of the following signatures:
  49  * <p>
  50  * void <METHOD>(InvocationContext)
  51  * <p>
  52  * Object <METHOD>(InvocationContext) throws Exception
  53  * <p>
  54  * <i>Note: A PostConstruct interceptor method must not throw application
  55  * exceptions, but it may be declared to throw checked exceptions including
  56  * the java.lang.Exception if the same interceptor method interposes on
  57  * business or timeout methods in addition to lifecycle events. If a
  58  * PostConstruct interceptor method returns a value, it is ignored by
  59  * the container.</i>
  60  * </li>
  61  * <li>The method defined on a non-interceptor class must have the
  62  * following signature:
  63  * <p>
  64  * void <METHOD>()
  65  * </li>
  66  * <li>The method on which the <code>PostConstruct</code> annotation
  67  * is applied may be public, protected, package private or private.</li>
  68  * <li>The method must not be static except for the application client.</li>
  69  * <li>The method should not be final.</li>
  70  * <li>If the method throws an unchecked exception the class must not be put into
  71  * service except in the case where the exception is handled by an
  72  * interceptor.</li></ul>
  73  *
  74  * @see javax.annotation.PreDestroy
  75  * @see javax.annotation.Resource
  76  * @since 1.6, Common Annotations 1.0
  77  */
  78 @Documented
  79 @Retention (RUNTIME)
  80 @Target(METHOD)
  81 public @interface PostConstruct {
  82 }