Announcement Announcement Module
Collapse
No announcement yet.
Turning Off Schema Validation in JUnit Causes Persistence Failures Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Turning Off Schema Validation in JUnit Causes Persistence Failures

    I am trying to test the following thread (because I want to turn off schema validation in a war which bootstraps the context files). I am using Spring 3.0.5 and JPA 2.0/Hibernate 3.6.5.

    https://jira.springsource.org/browse/SPR-5014
    http://stackoverflow.com/questions/4...on-in-spring-3

    So I am doing the same type of concept because in JUnits we use the ContextConfiguration annotation on the JUnit class where I can specify a custom loader. So I did the following:

    Code:
    import org.springframework.beans.factory.support.BeanDefinitionReader;
    import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
    import org.springframework.context.support.GenericApplicationContext;
    import org.springframework.test.context.support.GenericXmlContextLoader;
    
    public class ServiceGenericContextLoader extends GenericXmlContextLoader {
    
        @Override
        protected BeanDefinitionReader createBeanDefinitionReader(final GenericApplicationContext context) {
            XmlBeanDefinitionReader reader = (XmlBeanDefinitionReader) super.createBeanDefinitionReader(context);
            reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
            return reader;
        }
    
    }
    The problem is if I try to set the VALIDATION_NONE on the reader, then all my JPA/ORM persistence files start failing saying that the persistence.xml cannot be found.

    Code:
    Caused by: java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml}
    	at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.obtainDefaultPersistenceUnitInfo(DefaultPersistenceUnitManager.java:373)
    	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.determinePersistenceUnitInfo(LocalContainerEntityManagerFactoryBean.java:247)
    	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:196)
    	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    	... 50 more
    So I want to verify that this works through JUnit before I try to hookup this to my web.xml via the contextClass.

    The examples from other posts seem to assume you are manually loading the context files as opposed to using bootstrap methods via web.xml/war deployment or the ContextConfiguration via JUnit.

    Is there a better way to disable validation of spring schemas?

  • #2
    I found the answer in the following thread:

    https://jira.springsource.org/browse/OSGI-364

    The following line has to be added:

    reader.setNamespaceAware(true);

    Comment

    Working...
    X