Announcement Announcement Module
Collapse
No announcement yet.
How to disable XSD validation in Spring during server start-up? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to disable XSD validation in Spring during server start-up?

    Hi,

    Spring has various configuration files like ( Security, cache ) each depending on its own schema definition (XSD). All these files are present somewhere in the internet. whenever we start the server, all these config files are validated against this XSD which takes a lot of time start the server. In our case, it is between 5-10 mins.

    All we want to do is to disable these validations in developers machine. I searched the web and found this code.

    package com.app.framework.web.context;

    import org.springframework.beans.BeansException;
    import org.springframework.beans.factory.xml.XmlBeanDefin itionReader;
    import org.springframework.context.support.ClassPathXmlAp plicationContext;

    public class CustomClassPathXmlApplicationContext extends ClassPathXmlApplicationContext {
    @SuppressWarnings("unchecked")
    public CustomClassPathXmlApplicationContext(String s, Class aClass) throws BeansException {
    super(s, aClass);
    }

    public CustomClassPathXmlApplicationContext(String s) throws BeansException {
    super(s);
    }

    public CustomClassPathXmlApplicationContext(String[] s) throws BeansException {
    super(s);
    }

    protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) {
    beanDefinitionReader.setValidationMode(XmlBeanDefi nitionReader.VALIDATION_NONE);
    beanDefinitionReader.setNamespaceAware(true);
    }
    }

    This one disables the validation in "initBeanDefinitionReader" method. I made this change and added a bean entry in our config.xml file.

    Now, this bean is initialized and loaded into the classpath. Since, I have not tied this bean to web application context it doesn't pick this up during startup because of this even now validations are happening.

    Can anybody guide us on how to tie this up to the web context? If our approach is totally wrong, please guide us on how to resolve the issue. This has been eating our development time a lot.

    Thanks.

  • #2
    Hi,

    Take a look here, if you haven't already: http://forum.springsource.org/showthread.php?t=43439

    I'm guessing something like this in web.xml would tie the custom class to the web context:

    Code:
    <context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    
    <context-param>
    		<param-name>contextClass</param-name>
    		<param-value>your.custom.CustomClassPathXmlApplicationContext </param-value>
    </context-param>
    
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>

    Comment

    Working...
    X