001/*
002 * Copyright 2002-2019 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 at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * 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 and
014 * limitations under the License.
015 */
016
017package org.springframework.context.annotation;
018
019import org.springframework.beans.factory.support.BeanDefinitionRegistry;
020import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
021import org.springframework.core.type.AnnotationMetadata;
022
023/**
024 * Interface to be implemented by types that register additional bean definitions when
025 * processing @{@link Configuration} classes. Useful when operating at the bean definition
026 * level (as opposed to {@code @Bean} method/instance level) is desired or necessary.
027 *
028 * <p>Along with {@code @Configuration} and {@link ImportSelector}, classes of this type
029 * may be provided to the @{@link Import} annotation (or may also be returned from an
030 * {@code ImportSelector}).
031 *
032 * <p>An {@link ImportBeanDefinitionRegistrar} may implement any of the following
033 * {@link org.springframework.beans.factory.Aware Aware} interfaces, and their respective
034 * methods will be called prior to {@link #registerBeanDefinitions}:
035 * <ul>
036 * <li>{@link org.springframework.context.EnvironmentAware EnvironmentAware}</li>
037 * <li>{@link org.springframework.beans.factory.BeanFactoryAware BeanFactoryAware}
038 * <li>{@link org.springframework.beans.factory.BeanClassLoaderAware BeanClassLoaderAware}
039 * <li>{@link org.springframework.context.ResourceLoaderAware ResourceLoaderAware}
040 * </ul>
041 *
042 * <p>See implementations and associated unit tests for usage examples.
043 *
044 * @author Chris Beams
045 * @since 3.1
046 * @see Import
047 * @see ImportSelector
048 * @see Configuration
049 */
050public interface ImportBeanDefinitionRegistrar {
051
052        /**
053         * Register bean definitions as necessary based on the given annotation metadata of
054         * the importing {@code @Configuration} class.
055         * <p>Note that {@link BeanDefinitionRegistryPostProcessor} types may <em>not</em> be
056         * registered here, due to lifecycle constraints related to {@code @Configuration}
057         * class processing.
058         * @param importingClassMetadata annotation metadata of the importing class
059         * @param registry current bean definition registry
060         */
061        void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry);
062
063}