Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-5014

Provide options in ClassPathXmlApplicationContext to disable XSD Validation

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 2.5.5
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      Disabling XSD validation provides a significant speed boost when the container starts up. Currently, ClassPathXmlApplicationContext does not provide a facility to disable XSD validation in a straight forward manner. Even though it is possible to do so by subclassing ClassPathXmlApplicationContext, it would be better to allow users to enable / disable XSD validation through the ClassPathXmlApplicationContext itself.

      As of Spring 2.5, XSD validation is not required to the framework to function properly. [Ref: SPR-3894]

      This can be done with a minor code change in ClassPathXmlApplicationContext as follows:

      public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext {

      private Resource[] configResources;
      private boolean validation = true; // validation is enabled by default

      protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) {

      // If XSD validation is disabled
      if (! validation)

      { beanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE); beanDefinitionReader.setNamespaceAware(true); }

      }

      // Provide overloaded constructors to enable / disable validation
      public ClassPathXmlApplicationContext(String configLocation, boolean validation) throws BeansException {
      this(new String[]

      {configLocation}

      , true, null);
      this.validation = validation;
      }

      // < REST OF CODE OMMITED>
      }

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              yohan Yohan Liyanage
              Last updater:
              Trevor Marshall
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                8 years, 14 weeks ago