|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -25,7 +25,6 @@ import org.w3c.dom.Node; |
|
|
|
import org.w3c.dom.NodeList; |
|
|
|
import org.w3c.dom.NodeList; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.FatalBeanException; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.config.BeanDefinition; |
|
|
|
import org.springframework.beans.factory.config.BeanDefinition; |
|
|
|
import org.springframework.beans.factory.config.BeanDefinitionHolder; |
|
|
|
import org.springframework.beans.factory.config.BeanDefinitionHolder; |
|
|
|
import org.springframework.beans.factory.parsing.BeanComponentDefinition; |
|
|
|
import org.springframework.beans.factory.parsing.BeanComponentDefinition; |
|
|
|
@ -216,6 +215,10 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser { |
|
|
|
scanner.addExcludeFilter(typeFilter); |
|
|
|
scanner.addExcludeFilter(typeFilter); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (ClassNotFoundException ex) { |
|
|
|
|
|
|
|
parserContext.getReaderContext().warning( |
|
|
|
|
|
|
|
"Ignoring non-present type filter class: " + ex, parserContext.extractSource(element)); |
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) { |
|
|
|
parserContext.getReaderContext().error( |
|
|
|
parserContext.getReaderContext().error( |
|
|
|
ex.getMessage(), parserContext.extractSource(element), ex.getCause()); |
|
|
|
ex.getMessage(), parserContext.extractSource(element), ex.getCause()); |
|
|
|
@ -225,39 +228,34 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
protected TypeFilter createTypeFilter( |
|
|
|
protected TypeFilter createTypeFilter(Element element, @Nullable ClassLoader classLoader, |
|
|
|
Element element, @Nullable ClassLoader classLoader, ParserContext parserContext) { |
|
|
|
ParserContext parserContext) throws ClassNotFoundException { |
|
|
|
|
|
|
|
|
|
|
|
String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE); |
|
|
|
String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE); |
|
|
|
String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE); |
|
|
|
String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE); |
|
|
|
expression = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(expression); |
|
|
|
expression = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(expression); |
|
|
|
try { |
|
|
|
if ("annotation".equals(filterType)) { |
|
|
|
if ("annotation".equals(filterType)) { |
|
|
|
return new AnnotationTypeFilter((Class<Annotation>) ClassUtils.forName(expression, classLoader)); |
|
|
|
return new AnnotationTypeFilter((Class<Annotation>) ClassUtils.forName(expression, classLoader)); |
|
|
|
} |
|
|
|
} |
|
|
|
else if ("assignable".equals(filterType)) { |
|
|
|
else if ("assignable".equals(filterType)) { |
|
|
|
return new AssignableTypeFilter(ClassUtils.forName(expression, classLoader)); |
|
|
|
return new AssignableTypeFilter(ClassUtils.forName(expression, classLoader)); |
|
|
|
} |
|
|
|
} |
|
|
|
else if ("aspectj".equals(filterType)) { |
|
|
|
else if ("aspectj".equals(filterType)) { |
|
|
|
return new AspectJTypeFilter(expression, classLoader); |
|
|
|
return new AspectJTypeFilter(expression, classLoader); |
|
|
|
} |
|
|
|
} |
|
|
|
else if ("regex".equals(filterType)) { |
|
|
|
else if ("regex".equals(filterType)) { |
|
|
|
return new RegexPatternTypeFilter(Pattern.compile(expression)); |
|
|
|
return new RegexPatternTypeFilter(Pattern.compile(expression)); |
|
|
|
} |
|
|
|
} |
|
|
|
else if ("custom".equals(filterType)) { |
|
|
|
else if ("custom".equals(filterType)) { |
|
|
|
Class<?> filterClass = ClassUtils.forName(expression, classLoader); |
|
|
|
Class<?> filterClass = ClassUtils.forName(expression, classLoader); |
|
|
|
if (!TypeFilter.class.isAssignableFrom(filterClass)) { |
|
|
|
if (!TypeFilter.class.isAssignableFrom(filterClass)) { |
|
|
|
throw new IllegalArgumentException( |
|
|
|
throw new IllegalArgumentException( |
|
|
|
"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression); |
|
|
|
"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return (TypeFilter) BeanUtils.instantiateClass(filterClass); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("Unsupported filter type: " + filterType); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return (TypeFilter) BeanUtils.instantiateClass(filterClass); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (ClassNotFoundException ex) { |
|
|
|
else { |
|
|
|
throw new FatalBeanException("Type filter class not found: " + expression, ex); |
|
|
|
throw new IllegalArgumentException("Unsupported filter type: " + filterType); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|