| 1 | /* |
| 2 | * Copyright (c) 2005, 2020 Oracle and/or its affiliates. All rights reserved. |
| 3 | * |
| 4 | * This program and the accompanying materials are made available under the |
| 5 | * terms of the Eclipse Public License v. 2.0, which is available at |
| 6 | * http://www.eclipse.org/legal/epl-2.0. |
| 7 | * |
| 8 | * This Source Code may also be made available under the following Secondary |
| 9 | * Licenses when the conditions for such availability set forth in the |
| 10 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| 11 | * version 2 with the GNU Classpath Exception, which is available at |
| 12 | * https://www.gnu.org/software/classpath/license.html. |
| 13 | * |
| 14 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| 15 | */ |
| 16 | |
| 17 | package jakarta.annotation; |
| 18 | |
| 19 | import java.lang.annotation.*; |
| 20 | import static java.lang.annotation.ElementType.*; |
| 21 | import static java.lang.annotation.RetentionPolicy.*; |
| 22 | |
| 23 | /** |
| 24 | * The <code>PostConstruct</code> annotation is used on a method that |
| 25 | * needs to be executed after dependency injection is done to perform |
| 26 | * any initialization. This method must be invoked before the class |
| 27 | * is put into service. This annotation must be supported on all classes |
| 28 | * that support dependency injection. The method annotated with |
| 29 | * <code>PostConstruct</code> must be invoked even if the class does |
| 30 | * not request any resources to be injected. Only one |
| 31 | * method in a given class can be annotated with this annotation. |
| 32 | * The method on which the <code>PostConstruct</code> annotation is |
| 33 | * applied must fulfill all of the following criteria: |
| 34 | * <ul> |
| 35 | * <li>The method must not have any parameters except in the case of |
| 36 | * interceptors in which case it takes an <code>InvocationContext</code> |
| 37 | * object as defined by the Jakarta Interceptors specification.</li> |
| 38 | * <li>The method defined on an interceptor class or superclass of an |
| 39 | * interceptor class must have one of the following signatures: |
| 40 | * <p> |
| 41 | * void <METHOD>(InvocationContext) |
| 42 | * <p> |
| 43 | * Object <METHOD>(InvocationContext) throws Exception |
| 44 | * <p> |
| 45 | * <i>Note: A PostConstruct interceptor method must not throw application |
| 46 | * exceptions, but it may be declared to throw checked exceptions including |
| 47 | * the java.lang.Exception if the same interceptor method interposes on |
| 48 | * business or timeout methods in addition to lifecycle events. If a |
| 49 | * PostConstruct interceptor method returns a value, it is ignored by |
| 50 | * the container.</i> |
| 51 | * </li> |
| 52 | * <li>The method defined on a non-interceptor class must have the |
| 53 | * following signature: |
| 54 | * <p> |
| 55 | * void <METHOD>() |
| 56 | * </li> |
| 57 | * <li>The method on which the <code>PostConstruct</code> annotation |
| 58 | * is applied may be public, protected, package private or private.</li> |
| 59 | * <li>The method must not be static except for the application client.</li> |
| 60 | * <li>The method should not be final.</li> |
| 61 | * <li>If the method throws an unchecked exception the class must not be put into |
| 62 | * service except in the case where the exception is handled by an |
| 63 | * interceptor.</li></ul> |
| 64 | * |
| 65 | * @see jakarta.annotation.PreDestroy |
| 66 | * @see jakarta.annotation.Resource |
| 67 | * @since 1.6, Common Annotations 1.0 |
| 68 | */ |
| 69 | @Documented |
| 70 | @Retention (RUNTIME) |
| 71 | @Target(METHOD) |
| 72 | public @interface PostConstruct { |
| 73 | } |