java.lang.ClassCastException:org.apache.xerces.jaxp.DocumentBuilderFactoryImpl无法强制转换为javax.xml.parsers.DocumentBuilderFactory

时间:2016-01-21 09:37:09

标签: java maven jboss jboss5.x xerces

我在项目中使用java1.6jboss5.1Spring maven 3.2.5。我正在

  

java.lang.ClassCastException:org.apache.xerces.jaxp.DocumentBuilderFactoryImpl无法强制转换为javax.xml.parsers.DocumentBuilderFactory

这是我的Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.varun.batch</groupId>
    <artifactId>myproject</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>myproject Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <!-- Spring ORM support -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>3.2.13.RELEASE</version>
        </dependency>

        <!-- Spring Batch -->
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-core</artifactId>
            <version>3.0.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-infrastructure</artifactId>
            <version>3.0.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2</artifactId>
            <version>1.6.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.5.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-transport-local</artifactId>
            <version>1.6.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-transport-http</artifactId>
            <version>1.6.1</version>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.9</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>3.1.0.CR2</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.3.1.ga</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.3.0.CR2</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>3.3.0.CR2</version>
            <exclusions>
                <exclusion>
                    <artifactId>jboss-logging</artifactId>
                    <groupId>org.jboss.logging</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>


        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.1</version>
        </dependency>
        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
            <version>2.7.7</version>
        </dependency>
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>stax</groupId>
            <artifactId>stax-api</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-kernel</artifactId>
            <version>1.6.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>servlet-api</artifactId>
                    <groupId>javax.servlet</groupId>
                </exclusion>

            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-api</artifactId>
            <version>1.2.12</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-activation_1.1_spec</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-javamail_1.4_spec</artifactId>
            <version>1.6</version>
        </dependency>


        <dependency>
            <groupId>jaxen</groupId>
            <artifactId>jaxen</artifactId>
            <version>1.1.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>xercesImpl</artifactId>
                    <groupId>xerces</groupId>

                </exclusion>
                <exclusion>
                    <artifactId>xml-apis</artifactId>
                    <groupId>xml-apis</groupId>

                </exclusion>
                <exclusion>
                    <artifactId>xmlParserAPIs</artifactId>
                    <groupId>xerces</groupId>

                </exclusion>
            </exclusions>
        </dependency> 


        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-stax-api_1.0_spec</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-impl</artifactId>
            <version>1.2.12</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.codehaus.woodstox</groupId>
            <artifactId>wstx-asl</artifactId>
            <version>3.2.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jta_1.1_spec</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.schema</groupId>
            <artifactId>XmlSchema</artifactId>
            <version>1.4.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.0</version>
        </dependency>
        <dependency>
            <groupId>com.javaetmoi.core</groupId>
            <artifactId>javaetmoi-spring4-vfs2-support</artifactId>
            <version>1.4.0</version>
        </dependency> 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.2.13.RELEASE</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>3.2.13.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>3.2.13.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>3.2.13.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.retry</groupId>
            <artifactId>spring-retry</artifactId>
            <version>1.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc5</artifactId>
            <version>11.2.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.11</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.4</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
        </dependency>
        <dependency>
            <groupId>logkit</groupId>
            <artifactId>logkit</artifactId>
            <version>1.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <version>1.7.11</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>3.2.13.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.7</version>
        </dependency>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.18.1-GA</version>
        </dependency>
        <dependency>
            <groupId>javax.batch</groupId>
            <artifactId>javax.batch-api</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>3.2.13.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.13.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.3.0.Final</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
                <version>1.6.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsdl2code</goal>
                        </goals>
                        <configuration>
                            <unpackClasses>true</unpackClasses>
                            <packageName>com.globalss.data.processor.service</packageName>
                            <wsdlFile>src/main/resources/wsdl/MonitoringService.wsdl</wsdlFile>
                            <databindingName>xmlbeans</databindingName>
                            <syncMode>sync</syncMode>
                            <generateServerSide>true</generateServerSide>
                            <generateServicesXml>true</generateServicesXml>
                            <generateServerSideInterface>true</generateServerSideInterface>

                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>target/generated-sources/axis2/wsdl2code/resources</directory>
            </resource>
            <resource>
                <directory>target/generated-sources/xmlbeans/resources</directory>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java/com/globalss/dnb/monitor/model/</directory>
                <targetPath>com/globalss/dnb/monitor/model/</targetPath>
                <includes>
                    <include>*.hbm.xml</include>
                </includes>
            </resource>
        </resources>

    </build>
</project>

我尝试了多种解决方案,但无法解决。

第一种方法) 在jboss-5.1.0.GA \ lib \ endorsed文件夹中,我有这个jar (xercesImpl)。 所以我删除了那个jar,然后运行该项目。

现在我得到了这个例外

  

xception将上下文初始化事件发送到侦听器实例   class org.springframework.web.context.ContextLoaderListener   org.springframework.beans.factory.BeanDefinitionStoreException:   从类路径资源解析XML文档时发生意外异常   [弹簧分批context.xml中];嵌套异常是   javax.xml.parsers.FactoryConfigurationError:Provider的提供者   无法找到javax.xml.parsers.DocumentBuilderFactory

2nd)方法 我试过从pom.xml

评论了轰鸣声依赖
<dependency>
    <groupId>jaxen</groupId>
    <artifactId>jaxen</artifactId>
    <version>1.1.1</version>
    <exclusions>
        <exclusion>
            <artifactId>xercesImpl</artifactId>
            <groupId>xerces</groupId>
        </exclusion>
        <exclusion>
            <artifactId>xml-apis</artifactId>
            <groupId>xml-apis</groupId>
        </exclusion>
        <exclusion>
            <artifactId>xmlParserAPIs</artifactId>
            <groupId>xerces</groupId>
        </exclusion>
    </exclusions>
</dependency> 

但是我得到了同样的例外

  

org.springframework.beans.factory.BeanDefinitionStoreException:   从类路径资源解析XML文档时发生意外异常   [弹簧分批context.xml中];嵌套异常是   java.lang.ClassCastException:   org.apache.xerces.jaxp.DocumentBuilderFactoryImpl无法强制转换为   javax.xml.parsers.DocumentBuilderFactory at   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:413)

3rd)方法 我看到了一些关于同一问题的解决方案,解决方案说要添加波纹管依赖性

<dependency>
  <groupId>xerces</groupId>
  <artifactId>xercesImpl</artifactId>
  <version>2.11.0</version>
</dependency>

在我的pom.xml中添加上面的依赖项 我得到了这个例外

  

org.jboss.xb.binding.JBossXBRuntimeException:无法创建新的   SAX解析器在   org.jboss.xb.binding.UnmarshallerFactory $ UnmarshallerFactoryImpl.newUnmarshaller(UnmarshallerFactory.java:100)     在   org.jboss.web.tomcat.service.deployers.JBossContextConfig.processContextConfig(JBossContextConfig.java:549)     在   org.jboss.web.tomcat.service.deployers.JBossContextConfig.init(JBossContextConfig.java:536)     在   org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:279)     在   org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)     在   org.apache.catalina.core.StandardContext.init(StandardContext.java:5436)     在   org.apache.catalina.core.StandardContext.start(StandardContext.java:4148)

4th)方法 我也尝试删除这个罐子 enter image description here

这也适合我。

我对这个例外感到非常沮丧,但我无法解决这个问题,

此链接非常好,它解决了同样的问题,但我仍然无法解决这个问题,任何人都可以帮助我。 Dealing with "Xerces hell" in Java/Maven?

已修改

我找到了根本原因。 这是来自Jboss 5.1 Run-time

的快照

enter image description here

这是来自Maven dependency的快照 enter image description here

所以这两个罐子是冲突的。

所以我做了什么。构建项目后,我从(xml-api1.0.b2.jar)中删除了Myproject.war并在Jboos中手动部署了项目,并且jboss不会抛出错误。

但是当我不从(xml-api1.0.b2.jar)中移除myproject.war并在jboss中部署时,它会抛出相同的错误。

所以我必须从pom.xml删除依赖项。

for (xml-api1.0.b2.jar)我已经定义了波纹管依赖

<dependency>
    <groupId>jaxen</groupId>
    <artifactId>jaxen</artifactId>
    <version>1.1.1</version>
    <exclusions>
        <exclusion>
            <artifactId>xercesImpl</artifactId>
            <groupId>xerces</groupId>
        </exclusion>
        <exclusion>
            <artifactId>xml-apis</artifactId>
            <groupId>xml-apis</groupId>
        </exclusion>
        <exclusion>
            <artifactId>xmlParserAPIs</artifactId>
            <groupId>xerces</groupId>
        </exclusion>
    </exclusions>
</dependency> 

但是当我从pom.xml评论此依赖关系时,我仍然在Maven依赖项中获取jar,就像我在图像中所示。

我真的没有从(xml-api1.0.b2.jar)卡住的地方开始。任何人都可以通过查看pom.xml让我这么做。

1 个答案:

答案 0 :(得分:0)

xml-api1.0.b2.jar 由以下人员导入: poi-3.9 。   poi-3.9 取决于dom4j,而dom4j包含 xml-api1.0.b2  所以,你可以将poi升级到 3.16 ,它将解决这个问题。