Unbelievable: Cannot cast from class X to its super class

Posted by Phuong Nguyen de ManCity fan on Stack Overflow See other posts from Stack Overflow or by Phuong Nguyen de ManCity fan
Published on 2010-04-12T04:29:56Z Indexed on 2010/04/12 4:33 UTC
Read the original article Hit count: 380

I'm encountering a very weird problem with Spring (3.0.1.RELEASE), TestNG (5.11) and Maven Surefire (2.5). I have a test class that extends a Spring helper class for testNG so that test context can be loaded from an xml file (that contains some bean definitions). My project was imported into eclipse using m2eclipse (using Import Maven Project) The class run fine in Eclipse TestNG runner. However, it throws this exception with Maven Surefire

Caused by: java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
 at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:123)
 at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:89)
 at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:70)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)

I have eliminated all involved dependencies in my pom so that the two classes com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl and javax.xml.parsers.DocumentBuilderFactory are coming from JRE only (the rt.jar).

So, it looks so unbelievable to me.

I wonder if there is any mechanism in loading class that can explain for this behavior?

Thanks.

© Stack Overflow or respective owner

Related posts about maven-2

Related posts about surefire