001/*002 * Copyright 2002-2015 the original author or authors.003 *004 * Licensed under the Apache License, Version 2.0 (the "License");005 * you may not use this file except in compliance with the License.006 * You may obtain a copy of the License at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * distributed under the License is distributed on an "AS IS" BASIS,012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.013 * See the License for the specific language governing permissions and014 * limitations under the License.015 */016017package org.springframework.beans.factory.annotation;018019import java.io.IOException;020import java.io.ObjectInputStream;021import java.io.Serializable;022import java.lang.annotation.Annotation;023import java.lang.reflect.InvocationTargetException;024import java.lang.reflect.Method;025import java.lang.reflect.Modifier;026import java.util.Collection;027import java.util.LinkedHashSet;028import java.util.LinkedList;029import java.util.Map;030import java.util.Set;031import java.util.concurrent.ConcurrentHashMap;032033import org.apache.commons.logging.Log;034import org.apache.commons.logging.LogFactory;035036import org.springframework.beans.BeansException;037import org.springframework.beans.factory.BeanCreationException;038import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;039import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;040import org.springframework.beans.factory.support.RootBeanDefinition;041import org.springframework.core.Ordered;042import org.springframework.core.PriorityOrdered;043import org.springframework.util.ClassUtils;044import org.springframework.util.ReflectionUtils;045046/**047 * {@link org.springframework.beans.factory.config.BeanPostProcessor} implementation048 * that invokes annotated init and destroy methods. Allows for an annotation049 * alternative to Spring's {@link org.springframework.beans.factory.InitializingBean}050 * and {@link org.springframework.beans.factory.DisposableBean} callback interfaces.051 *052 * <p>The actual annotation types that this post-processor checks for can be053 * configured through the {@link #setInitAnnotationType "initAnnotationType"}054 * and {@link #setDestroyAnnotationType "destroyAnnotationType"} properties.055 * Any custom annotation can be used, since there are no required annotation056 * attributes.057 *058 * <p>Init and destroy annotations may be applied to methods of any visibility:059 * public, package-protected, protected, or private. Multiple such methods060 * may be annotated, but it is recommended to only annotate one single061 * init method and destroy method, respectively.062 *063 * <p>Spring's {@link org.springframework.context.annotation.CommonAnnotationBeanPostProcessor}064 * supports the JSR-250 {@link javax.annotation.PostConstruct} and {@link javax.annotation.PreDestroy}065 * annotations out of the box, as init annotation and destroy annotation, respectively.066 * Furthermore, it also supports the {@link javax.annotation.Resource} annotation067 * for annotation-driven injection of named beans.068 *069 * @author Juergen Hoeller070 * @since 2.5