1717package  org .springframework .beans .factory .xml ;
1818
1919import  java .io .IOException ;
20+ import  java .net .URISyntaxException ;
2021import  java .util .LinkedHashSet ;
2122import  java .util .Set ;
2223
2324import  org .apache .commons .logging .Log ;
2425import  org .apache .commons .logging .LogFactory ;
26+ import  org .w3c .dom .Document ;
27+ import  org .w3c .dom .Element ;
28+ import  org .w3c .dom .Node ;
29+ import  org .w3c .dom .NodeList ;
30+ 
2531import  org .springframework .beans .factory .BeanDefinitionStoreException ;
2632import  org .springframework .beans .factory .config .BeanDefinitionHolder ;
2733import  org .springframework .beans .factory .parsing .BeanComponentDefinition ;
3137import  org .springframework .util .ResourceUtils ;
3238import  org .springframework .util .StringUtils ;
3339import  org .springframework .util .SystemPropertyUtils ;
34- import  org .w3c .dom .Document ;
35- import  org .w3c .dom .Element ;
36- import  org .w3c .dom .Node ;
37- import  org .w3c .dom .NodeList ;
3840
3941/** 
4042 * Default implementation of the {@link BeanDefinitionDocumentReader} interface. 
@@ -171,15 +173,15 @@ protected void importBeanDefinitionResource(Element ele) {
171173
172174		// Discover whether the location is an absolute or relative URI  
173175		boolean  absoluteLocation  = false ;
174- 		
175176		try  {
176177			absoluteLocation  = ResourcePatternUtils .isUrl (location ) || ResourceUtils .toURI (location ).isAbsolute ();
177- 		} catch  (Exception  ex ) {
178+ 		}
179+ 		catch  (URISyntaxException  ex ) {
178180			// cannot convert to an URI, considering the location relative 
179- 			// unless it is the well-known Spring prefix classpath*:   
181+ 			// unless it is the well-known Spring prefix " classpath*:"  
180182		}
181- 		 
182- 		// check the   
183+ 
184+ 		// Absolute or relative?  
183185		if  (absoluteLocation ) {
184186			try  {
185187				int  importCount  = getReaderContext ().getReader ().loadBeanDefinitions (location , actualResources );
@@ -195,9 +197,17 @@ protected void importBeanDefinitionResource(Element ele) {
195197		else  {
196198			// No URL -> considering resource location as relative to the current file. 
197199			try  {
198- 				String  baseLocation  = getReaderContext ().getResource ().getURL ().toString ();
199- 				int  importCount  = getReaderContext ().getReader ().loadBeanDefinitions (
200- 						StringUtils .applyRelativePath (baseLocation , location ), actualResources );
200+ 				int  importCount ;
201+ 				Resource  relativeResource  = getReaderContext ().getResource ().createRelative (location );
202+ 				if  (relativeResource .exists ()) {
203+ 					importCount  = getReaderContext ().getReader ().loadBeanDefinitions (relativeResource );
204+ 					actualResources .add (relativeResource );
205+ 				}
206+ 				else  {
207+ 					String  baseLocation  = getReaderContext ().getResource ().getURL ().toString ();
208+ 					importCount  = getReaderContext ().getReader ().loadBeanDefinitions (
209+ 							StringUtils .applyRelativePath (baseLocation , location ), actualResources );
210+ 				}
201211				if  (logger .isDebugEnabled ()) {
202212					logger .debug ("Imported "  + importCount  + " bean definitions from relative location ["  + location  + "]" );
203213				}
0 commit comments