import works with relative resources in other classpath roots again (SPR-6493)
This commit is contained in:
parent
231c8337d2
commit
09a55c8ede
|
@ -17,11 +17,17 @@
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||||
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;
|
||||||
|
@ -31,10 +37,6 @@ import org.springframework.core.io.support.ResourcePatternUtils;
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.util.SystemPropertyUtils;
|
import org.springframework.util.SystemPropertyUtils;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of the {@link BeanDefinitionDocumentReader} interface.
|
* Default implementation of the {@link BeanDefinitionDocumentReader} interface.
|
||||||
|
@ -171,15 +173,15 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
|
||||||
|
|
||||||
// Discover whether the location is an absolute or relative URI
|
// Discover whether the location is an absolute or relative URI
|
||||||
boolean absoluteLocation = false;
|
boolean absoluteLocation = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
absoluteLocation = ResourcePatternUtils.isUrl(location) || ResourceUtils.toURI(location).isAbsolute();
|
absoluteLocation = ResourcePatternUtils.isUrl(location) || ResourceUtils.toURI(location).isAbsolute();
|
||||||
} catch (Exception ex) {
|
|
||||||
// cannot convert to an URI, considering the location relative
|
|
||||||
// unless it is the well-known Spring prefix classpath*:
|
|
||||||
}
|
}
|
||||||
|
catch (URISyntaxException ex) {
|
||||||
// check the
|
// cannot convert to an URI, considering the location relative
|
||||||
|
// unless it is the well-known Spring prefix "classpath*:"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Absolute or relative?
|
||||||
if (absoluteLocation) {
|
if (absoluteLocation) {
|
||||||
try {
|
try {
|
||||||
int importCount = getReaderContext().getReader().loadBeanDefinitions(location, actualResources);
|
int importCount = getReaderContext().getReader().loadBeanDefinitions(location, actualResources);
|
||||||
|
@ -195,9 +197,17 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
|
||||||
else {
|
else {
|
||||||
// No URL -> considering resource location as relative to the current file.
|
// No URL -> considering resource location as relative to the current file.
|
||||||
try {
|
try {
|
||||||
String baseLocation = getReaderContext().getResource().getURL().toString();
|
int importCount;
|
||||||
int importCount = getReaderContext().getReader().loadBeanDefinitions(
|
Resource relativeResource = getReaderContext().getResource().createRelative(location);
|
||||||
StringUtils.applyRelativePath(baseLocation, location), actualResources);
|
if (relativeResource.exists()) {
|
||||||
|
importCount = getReaderContext().getReader().loadBeanDefinitions(relativeResource);
|
||||||
|
actualResources.add(relativeResource);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String baseLocation = getReaderContext().getResource().getURL().toString();
|
||||||
|
importCount = getReaderContext().getReader().loadBeanDefinitions(
|
||||||
|
StringUtils.applyRelativePath(baseLocation, location), actualResources);
|
||||||
|
}
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Imported " + importCount + " bean definitions from relative location [" + location + "]");
|
logger.debug("Imported " + importCount + " bean definitions from relative location [" + location + "]");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue