1
1
/*
2
- * Copyright 2002-2017 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 ;
@@ -216,6 +215,10 @@ else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
216
215
scanner .addExcludeFilter (typeFilter );
217
216
}
218
217
}
218
+ catch (ClassNotFoundException ex ) {
219
+ parserContext .getReaderContext ().warning (
220
+ "Ignoring non-present type filter class: " + ex , parserContext .extractSource (element ));
221
+ }
219
222
catch (Exception ex ) {
220
223
parserContext .getReaderContext ().error (
221
224
ex .getMessage (), parserContext .extractSource (element ), ex .getCause ());
@@ -225,39 +228,34 @@ else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
225
228
}
226
229
227
230
@ SuppressWarnings ("unchecked" )
228
- protected TypeFilter createTypeFilter (
229
- Element element , @ Nullable ClassLoader classLoader , ParserContext parserContext ) {
231
+ protected TypeFilter createTypeFilter (Element element , @ Nullable ClassLoader classLoader ,
232
+ ParserContext parserContext ) throws ClassNotFoundException {
230
233
231
234
String filterType = element .getAttribute (FILTER_TYPE_ATTRIBUTE );
232
235
String expression = element .getAttribute (FILTER_EXPRESSION_ATTRIBUTE );
233
236
expression = parserContext .getReaderContext ().getEnvironment ().resolvePlaceholders (expression );
234
- try {
235
- if ("annotation" .equals (filterType )) {
236
- return new AnnotationTypeFilter ((Class <Annotation >) ClassUtils .forName (expression , classLoader ));
237
- }
238
- else if ("assignable" .equals (filterType )) {
239
- return new AssignableTypeFilter (ClassUtils .forName (expression , classLoader ));
240
- }
241
- else if ("aspectj" .equals (filterType )) {
242
- return new AspectJTypeFilter (expression , classLoader );
243
- }
244
- else if ("regex" .equals (filterType )) {
245
- return new RegexPatternTypeFilter (Pattern .compile (expression ));
246
- }
247
- else if ("custom" .equals (filterType )) {
248
- Class <?> filterClass = ClassUtils .forName (expression , classLoader );
249
- if (!TypeFilter .class .isAssignableFrom (filterClass )) {
250
- throw new IllegalArgumentException (
251
- "Class is not assignable to [" + TypeFilter .class .getName () + "]: " + expression );
252
- }
253
- return (TypeFilter ) BeanUtils .instantiateClass (filterClass );
254
- }
255
- else {
256
- throw new IllegalArgumentException ("Unsupported filter type: " + filterType );
237
+ if ("annotation" .equals (filterType )) {
238
+ return new AnnotationTypeFilter ((Class <Annotation >) ClassUtils .forName (expression , classLoader ));
239
+ }
240
+ else if ("assignable" .equals (filterType )) {
241
+ return new AssignableTypeFilter (ClassUtils .forName (expression , classLoader ));
242
+ }
243
+ else if ("aspectj" .equals (filterType )) {
244
+ return new AspectJTypeFilter (expression , classLoader );
245
+ }
246
+ else if ("regex" .equals (filterType )) {
247
+ return new RegexPatternTypeFilter (Pattern .compile (expression ));
248
+ }
249
+ else if ("custom" .equals (filterType )) {
250
+ Class <?> filterClass = ClassUtils .forName (expression , classLoader );
251
+ if (!TypeFilter .class .isAssignableFrom (filterClass )) {
252
+ throw new IllegalArgumentException (
253
+ "Class is not assignable to [" + TypeFilter .class .getName () + "]: " + expression );
257
254
}
255
+ return (TypeFilter ) BeanUtils .instantiateClass (filterClass );
258
256
}
259
- catch ( ClassNotFoundException ex ) {
260
- throw new FatalBeanException ( "Type filter class not found : " + expression , ex );
257
+ else {
258
+ throw new IllegalArgumentException ( "Unsupported filter type : " + filterType );
261
259
}
262
260
}
263
261
0 commit comments