diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java
index 1790b85d0ff..f5552984eb0 100644
--- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java
+++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java
@@ -135,8 +135,21 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
}
+ /**
+ * Set whether to use XML validation. Default is true.
+ *
This method switches namespace awareness on if validation is turned off, + * in order to still process schema namespaces properly in such a scenario. + * @see #setValidationMode + * @see #setNamespaceAware + */ + public void setValidating(boolean validating) { + this.validationMode = (validating ? VALIDATION_AUTO : VALIDATION_NONE); + this.namespaceAware = !validating; + } + /** * Set the validation mode to use by name. Defaults to {@link #VALIDATION_AUTO}. + * @see #setValidationMode */ public void setValidationModeName(String validationModeName) { setValidationMode(constants.asNumber(validationModeName).intValue()); @@ -144,6 +157,9 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader { /** * Set the validation mode to use. Defaults to {@link #VALIDATION_AUTO}. + *
Note that this only activates or deactivates validation itself. + * If you are switching validation off for schema files, you might need to + * activate schema namespace support explicitly: see {@link #setNamespaceAware}. */ public void setValidationMode(int validationMode) { this.validationMode = validationMode; @@ -159,6 +175,9 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader { /** * Set whether or not the XML parser should be XML namespace aware. * Default is "false". + *
This is typically not needed when schema validation is active. + * However, without validation, this has to be switched to "true" + * in order to properly process schema namespaces. */ public void setNamespaceAware(boolean namespaceAware) { this.namespaceAware = namespaceAware; diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java index 69adb4f48be..51894a287fa 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java +++ b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java @@ -97,14 +97,11 @@ public abstract class AbstractXmlApplicationContext extends AbstractRefreshableC * definitions of this context. Default implementation is empty. *
Can be overridden in subclasses, e.g. for turning off XML validation
* or using a different XmlBeanDefinitionParser implementation.
- * @param beanDefinitionReader the bean definition reader used by this context
+ * @param reader the bean definition reader used by this context
* @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader#setDocumentReaderClass
*/
- protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) {
- if (!this.validating) {
- beanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
- beanDefinitionReader.setNamespaceAware(true);
- }
+ protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
+ reader.setValidating(this.validating);
}
/**
diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/GenericXmlApplicationContext.java b/org.springframework.context/src/main/java/org/springframework/context/support/GenericXmlApplicationContext.java
index 59ad199c251..1ac98d10a89 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/support/GenericXmlApplicationContext.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/support/GenericXmlApplicationContext.java
@@ -72,9 +72,7 @@ public class GenericXmlApplicationContext extends GenericApplicationContext {
* Set whether to use XML validation. Default is true.
*/
public void setValidating(boolean validating) {
- this.reader.setValidationMode(validating ?
- XmlBeanDefinitionReader.VALIDATION_AUTO : XmlBeanDefinitionReader.VALIDATION_NONE);
- this.reader.setNamespaceAware(!validating);
+ this.reader.setValidating(validating);
}