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 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 java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Retention;
022import java.lang.annotation.RetentionPolicy;
023import java.lang.annotation.Target;
024
025import org.springframework.beans.factory.support.BeanDefinitionReader;
026import org.springframework.core.annotation.AliasFor;
027
028/**
029 * Indicates one or more resources containing bean definitions to import.
030 *
031 * <p>Like {@link Import @Import}, this annotation provides functionality similar to
032 * the {@code <import/>} element in Spring XML. It is typically used when designing
033 * {@link Configuration @Configuration} classes to be bootstrapped by an
034 * {@link AnnotationConfigApplicationContext}, but where some XML functionality such
035 * as namespaces is still necessary.
036 *
037 * <p>By default, arguments to the {@link #value} attribute will be processed using a
038 * {@link org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader GroovyBeanDefinitionReader}
039 * if ending in {@code ".groovy"}; otherwise, an
040 * {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader XmlBeanDefinitionReader}
041 * will be used to parse Spring {@code <beans/>} XML files. Optionally, the {@link #reader}
042 * attribute may be declared, allowing the user to choose a custom {@link BeanDefinitionReader}
043 * implementation.
044 *
045 * @author Chris Beams
046 * @author Juergen Hoeller
047 * @author Sam Brannen
048 * @since 3.0
049 * @see Configuration
050 * @see Import
051 */
052@Retention(RetentionPolicy.RUNTIME)
053@Target(ElementType.TYPE)
054@Documented
055public @interface ImportResource {
056
057        /**
058         * Alias for {@link #locations}.
059         * @see #locations
060         * @see #reader
061         */
062        @AliasFor("locations")
063        String[] value() default {};
064
065        /**
066         * Resource locations from which to import.
067         * <p>Supports resource-loading prefixes such as {@code classpath:},
068         * {@code file:}, etc.
069         * <p>Consult the Javadoc for {@link #reader} for details on how resources
070         * will be processed.
071         * @since 4.2
072         * @see #value
073         * @see #reader
074         */
075        @AliasFor("value")
076        String[] locations() default {};
077
078        /**
079         * {@link BeanDefinitionReader} implementation to use when processing
080         * resources specified via the {@link #value} attribute.
081         * <p>By default, the reader will be adapted to the resource path specified:
082         * {@code ".groovy"} files will be processed with a
083         * {@link org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader GroovyBeanDefinitionReader};
084         * whereas, all other resources will be processed with an
085         * {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader XmlBeanDefinitionReader}.
086         * @see #value
087         */
088        Class<? extends BeanDefinitionReader> reader() default BeanDefinitionReader.class;
089
090}