11/*
2- * Copyright 2002-2017 the original author or authors.
2+ * Copyright 2002-2018 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2525import org .w3c .dom .NodeList ;
2626
2727import org .springframework .beans .BeanUtils ;
28- import org .springframework .beans .FatalBeanException ;
2928import org .springframework .beans .factory .config .BeanDefinition ;
3029import org .springframework .beans .factory .config .BeanDefinitionHolder ;
3130import org .springframework .beans .factory .parsing .BeanComponentDefinition ;
@@ -216,6 +215,10 @@ else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
216215 scanner .addExcludeFilter (typeFilter );
217216 }
218217 }
218+ catch (ClassNotFoundException ex ) {
219+ parserContext .getReaderContext ().warning (
220+ "Ignoring non-present type filter class: " + ex , parserContext .extractSource (element ));
221+ }
219222 catch (Exception ex ) {
220223 parserContext .getReaderContext ().error (
221224 ex .getMessage (), parserContext .extractSource (element ), ex .getCause ());
@@ -225,39 +228,34 @@ else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
225228 }
226229
227230 @ 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 {
230233
231234 String filterType = element .getAttribute (FILTER_TYPE_ATTRIBUTE );
232235 String expression = element .getAttribute (FILTER_EXPRESSION_ATTRIBUTE );
233236 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 );
257254 }
255+ return (TypeFilter ) BeanUtils .instantiateClass (filterClass );
258256 }
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 );
261259 }
262260 }
263261
0 commit comments