1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
25
25
import org .w3c .dom .NodeList ;
26
26
27
27
import org .springframework .beans .BeanUtils ;
28
- import org .springframework .beans .FatalBeanException ;
29
28
import org .springframework .beans .factory .config .BeanDefinition ;
30
29
import org .springframework .beans .factory .config .BeanDefinitionHolder ;
31
30
import org .springframework .beans .factory .parsing .BeanComponentDefinition ;
40
39
import org .springframework .core .type .filter .AssignableTypeFilter ;
41
40
import org .springframework .core .type .filter .RegexPatternTypeFilter ;
42
41
import org .springframework .core .type .filter .TypeFilter ;
42
+ import org .springframework .util .ClassUtils ;
43
43
import org .springframework .util .StringUtils ;
44
44
45
45
/**
@@ -212,6 +212,10 @@ else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
212
212
scanner .addExcludeFilter (typeFilter );
213
213
}
214
214
}
215
+ catch (ClassNotFoundException ex ) {
216
+ parserContext .getReaderContext ().warning (
217
+ "Ignoring non-present type filter class: " + ex , parserContext .extractSource (element ));
218
+ }
215
219
catch (Exception ex ) {
216
220
parserContext .getReaderContext ().error (
217
221
ex .getMessage (), parserContext .extractSource (element ), ex .getCause ());
@@ -221,37 +225,34 @@ else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
221
225
}
222
226
223
227
@ SuppressWarnings ("unchecked" )
224
- protected TypeFilter createTypeFilter (Element element , ClassLoader classLoader , ParserContext parserContext ) {
228
+ protected TypeFilter createTypeFilter (Element element , ClassLoader classLoader ,
229
+ ParserContext parserContext ) throws ClassNotFoundException {
230
+
225
231
String filterType = element .getAttribute (FILTER_TYPE_ATTRIBUTE );
226
232
String expression = element .getAttribute (FILTER_EXPRESSION_ATTRIBUTE );
227
233
expression = parserContext .getReaderContext ().getEnvironment ().resolvePlaceholders (expression );
228
- try {
229
- if ("annotation" .equals (filterType )) {
230
- return new AnnotationTypeFilter ((Class <Annotation >) classLoader .loadClass (expression ));
231
- }
232
- else if ("assignable" .equals (filterType )) {
233
- return new AssignableTypeFilter (classLoader .loadClass (expression ));
234
- }
235
- else if ("aspectj" .equals (filterType )) {
236
- return new AspectJTypeFilter (expression , classLoader );
237
- }
238
- else if ("regex" .equals (filterType )) {
239
- return new RegexPatternTypeFilter (Pattern .compile (expression ));
240
- }
241
- else if ("custom" .equals (filterType )) {
242
- Class <?> filterClass = classLoader .loadClass (expression );
243
- if (!TypeFilter .class .isAssignableFrom (filterClass )) {
244
- throw new IllegalArgumentException (
245
- "Class is not assignable to [" + TypeFilter .class .getName () + "]: " + expression );
246
- }
247
- return (TypeFilter ) BeanUtils .instantiateClass (filterClass );
248
- }
249
- else {
250
- throw new IllegalArgumentException ("Unsupported filter type: " + filterType );
234
+ if ("annotation" .equals (filterType )) {
235
+ return new AnnotationTypeFilter ((Class <Annotation >) ClassUtils .forName (expression , classLoader ));
236
+ }
237
+ else if ("assignable" .equals (filterType )) {
238
+ return new AssignableTypeFilter (ClassUtils .forName (expression , classLoader ));
239
+ }
240
+ else if ("aspectj" .equals (filterType )) {
241
+ return new AspectJTypeFilter (expression , classLoader );
242
+ }
243
+ else if ("regex" .equals (filterType )) {
244
+ return new RegexPatternTypeFilter (Pattern .compile (expression ));
245
+ }
246
+ else if ("custom" .equals (filterType )) {
247
+ Class <?> filterClass = ClassUtils .forName (expression , classLoader );
248
+ if (!TypeFilter .class .isAssignableFrom (filterClass )) {
249
+ throw new IllegalArgumentException (
250
+ "Class is not assignable to [" + TypeFilter .class .getName () + "]: " + expression );
251
251
}
252
+ return (TypeFilter ) BeanUtils .instantiateClass (filterClass );
252
253
}
253
- catch ( ClassNotFoundException ex ) {
254
- throw new FatalBeanException ( "Type filter class not found : " + expression , ex );
254
+ else {
255
+ throw new IllegalArgumentException ( "Unsupported filter type : " + filterType );
255
256
}
256
257
}
257
258
0 commit comments