001/* 002 * Copyright 2002-2020 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.core.type.AnnotationMetadata; 020 021/** 022 * Interface to be implemented by types that determine which @{@link Configuration} 023 * class(es) should be imported based on a given selection criteria, usually one or 024 * more annotation attributes. 025 * 026 * <p>An {@link ImportSelector} may implement any of the following 027 * {@link org.springframework.beans.factory.Aware Aware} interfaces, 028 * and their respective methods will be called prior to {@link #selectImports}: 029 * <ul> 030 * <li>{@link org.springframework.context.EnvironmentAware EnvironmentAware}</li> 031 * <li>{@link org.springframework.beans.factory.BeanFactoryAware BeanFactoryAware}</li> 032 * <li>{@link org.springframework.beans.factory.BeanClassLoaderAware BeanClassLoaderAware}</li> 033 * <li>{@link org.springframework.context.ResourceLoaderAware ResourceLoaderAware}</li> 034 * </ul> 035 * 036 * <p>{@code ImportSelector} implementations are usually processed in the same way 037 * as regular {@code @Import} annotations, however, it is also possible to defer 038 * selection of imports until all {@code @Configuration} classes have been processed 039 * (see {@link DeferredImportSelector} for details). 040 * 041 * @author Chris Beams 042 * @since 3.1 043 * @see DeferredImportSelector 044 * @see Import 045 * @see ImportBeanDefinitionRegistrar 046 * @see Configuration 047 */ 048public interface ImportSelector { 049 050 /** 051 * Select and return the names of which class(es) should be imported based on 052 * the {@link AnnotationMetadata} of the importing @{@link Configuration} class. 053 * @return the class names, or an empty array if none 054 */ 055 String[] selectImports(AnnotationMetadata importingClassMetadata); 056 057}