Introduce alias for 'value' attribute in @ComponentScan.Filter
Issue: SPR-11393
This commit is contained in:
@@ -157,10 +157,18 @@ public @interface ComponentScan {
|
||||
/**
|
||||
* The type of filter to use.
|
||||
* <p>Default is {@link FilterType#ANNOTATION}.
|
||||
* @see #classes
|
||||
* @see #pattern
|
||||
*/
|
||||
FilterType type() default FilterType.ANNOTATION;
|
||||
|
||||
/**
|
||||
* Alias for {@link #classes}.
|
||||
* @see #classes
|
||||
*/
|
||||
@AliasFor(attribute = "classes")
|
||||
Class<?>[] value() default {};
|
||||
|
||||
/**
|
||||
* The class or classes to use as the filter.
|
||||
* <p>The following table explains how the classes will be interpreted
|
||||
@@ -178,8 +186,12 @@ public @interface ComponentScan {
|
||||
* — for example, "include types annotated with {@code @Foo} OR {@code @Bar}".
|
||||
* <p>Specifying zero classes is permitted but will have no effect on component
|
||||
* scanning.
|
||||
* @since 4.2
|
||||
* @see #value
|
||||
* @see #type
|
||||
*/
|
||||
Class<?>[] value() default {};
|
||||
@AliasFor(attribute = "value")
|
||||
Class<?>[] classes() default {};
|
||||
|
||||
/**
|
||||
* The pattern (or patterns) to use for the filter, as an alternative
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,6 +47,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
* @see ClassPathBeanDefinitionScanner#scan(String...)
|
||||
* @see ComponentScanBeanDefinitionParser
|
||||
@@ -73,13 +74,12 @@ class ComponentScanAnnotationParser {
|
||||
|
||||
|
||||
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, final String declaringClass) {
|
||||
Assert.state(this.environment != null, "Environment must not be null");
|
||||
Assert.state(this.resourceLoader != null, "ResourceLoader must not be null");
|
||||
|
||||
ClassPathBeanDefinitionScanner scanner =
|
||||
new ClassPathBeanDefinitionScanner(this.registry, componentScan.getBoolean("useDefaultFilters"));
|
||||
|
||||
Assert.notNull(this.environment, "Environment must not be null");
|
||||
scanner.setEnvironment(this.environment);
|
||||
|
||||
Assert.notNull(this.resourceLoader, "ResourceLoader must not be null");
|
||||
scanner.setResourceLoader(this.resourceLoader);
|
||||
|
||||
Class<? extends BeanNameGenerator> generatorClass = componentScan.getClass("nameGenerator");
|
||||
@@ -141,7 +141,7 @@ class ComponentScanAnnotationParser {
|
||||
List<TypeFilter> typeFilters = new ArrayList<TypeFilter>();
|
||||
FilterType filterType = filterAttributes.getEnum("type");
|
||||
|
||||
for (Class<?> filterClass : filterAttributes.getClassArray("value")) {
|
||||
for (Class<?> filterClass : filterAttributes.getAliasedClassArray("classes", ComponentScan.Filter.class, null)) {
|
||||
switch (filterType) {
|
||||
case ANNOTATION:
|
||||
Assert.isAssignable(Annotation.class, filterClass,
|
||||
|
||||
Reference in New Issue
Block a user