Introduce alias for 'value' attribute in @ImportResource
Issue: SPR-11393
This commit is contained in:
@@ -94,6 +94,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
* @since 3.0
|
||||
* @see ConfigurationClassBeanDefinitionReader
|
||||
*/
|
||||
@@ -277,7 +278,7 @@ class ConfigurationClassParser {
|
||||
// Process any @ImportResource annotations
|
||||
if (sourceClass.getMetadata().isAnnotated(ImportResource.class.getName())) {
|
||||
AnnotationAttributes importResource = AnnotationConfigUtils.attributesFor(sourceClass.getMetadata(), ImportResource.class);
|
||||
String[] resources = importResource.getStringArray("value");
|
||||
String[] resources = importResource.getAliasedStringArray("locations", ImportResource.class, sourceClass);
|
||||
Class<? extends BeanDefinitionReader> readerClass = importResource.getClass("reader");
|
||||
for (String resource : resources) {
|
||||
String resolvedResource = this.environment.resolveRequiredPlaceholders(resource);
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Indicates one or more resources containing bean definitions to import.
|
||||
@@ -34,8 +35,9 @@ import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
* as namespaces is still necessary.
|
||||
*
|
||||
* <p>By default, arguments to the {@link #value} attribute will be processed using a
|
||||
* {@link org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader} if ending in
|
||||
* {@code ".groovy"}; otherwise, an {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}
|
||||
* {@link org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader GroovyBeanDefinitionReader}
|
||||
* if ending in {@code ".groovy"}; otherwise, an
|
||||
* {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader XmlBeanDefinitionReader}
|
||||
* will be used to parse Spring {@code <beans/>} XML files. Optionally, the {@link #reader}
|
||||
* attribute may be declared, allowing the user to choose a custom {@link BeanDefinitionReader}
|
||||
* implementation.
|
||||
@@ -53,23 +55,34 @@ import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
public @interface ImportResource {
|
||||
|
||||
/**
|
||||
* Resource locations from which to import.
|
||||
* <p>Supports resource-loading prefixes such as {@code classpath:}, {@code file:},
|
||||
* etc.
|
||||
* <p>Consult the Javadoc for {@link #reader} for details on how resources
|
||||
* will be processed.
|
||||
* Alias for {@link #locations}.
|
||||
* @see #locations
|
||||
* @see #reader
|
||||
*/
|
||||
String[] value();
|
||||
@AliasFor(attribute = "locations")
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* {@link BeanDefinitionReader} implementation to use when processing resources
|
||||
* specified via the {@link #value} attribute.
|
||||
* Resource locations from which to import.
|
||||
* <p>Supports resource-loading prefixes such as {@code classpath:},
|
||||
* {@code file:}, etc.
|
||||
* <p>Consult the Javadoc for {@link #reader} for details on how resources
|
||||
* will be processed.
|
||||
* @since 4.2
|
||||
* @see #value
|
||||
* @see #reader
|
||||
*/
|
||||
@AliasFor(attribute = "value")
|
||||
String[] locations() default {};
|
||||
|
||||
/**
|
||||
* {@link BeanDefinitionReader} implementation to use when processing
|
||||
* resources specified via the {@link #value} attribute.
|
||||
* <p>By default, the reader will be adapted to the resource path specified:
|
||||
* {@code ".groovy"} files will be processed with a
|
||||
* {@link org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader};
|
||||
* {@link org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader GroovyBeanDefinitionReader};
|
||||
* whereas, all other resources will be processed with an
|
||||
* {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}.
|
||||
* {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader XmlBeanDefinitionReader}.
|
||||
* @see #value
|
||||
*/
|
||||
Class<? extends BeanDefinitionReader> reader() default BeanDefinitionReader.class;
|
||||
|
||||
Reference in New Issue
Block a user