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

18 浏览
0 Comments

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

我的项目中使用了 java1.6jboss5.1Spring maven 3.2.5。我遇到了以下问题

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

这是我的 Pom.xml

    4.0.0
    com.varun.batch
    myproject
    war
    0.0.1-SNAPSHOT
    myproject Maven Webapp
    http://maven.apache.org
    
        
        
            org.springframework
            spring-orm
            3.2.13.RELEASE
        
        
        
            org.springframework.batch
            spring-batch-core
            3.0.1.RELEASE
        
        
            org.springframework.batch
            spring-batch-infrastructure
            3.0.1.RELEASE
        
        
            org.apache.axis2
            axis2
            1.6.2
        
        
            org.apache.xmlbeans
            xmlbeans
            2.5.0
        
        
            org.apache.axis2
            axis2-transport-local
            1.6.1
        
        
            org.apache.axis2
            axis2-transport-http
            1.6.1
        
        
            commons-codec
            commons-codec
            1.6
        
        
            org.apache.poi
            poi
            3.9
        
        
            org.hibernate.javax.persistence
            hibernate-jpa-2.0-api
            1.0.0.Final
        
        
            org.hibernate
            hibernate-validator
            3.1.0.CR2
            
                
                    org.slf4j
                    slf4j-api
                
            
        
        
            org.hibernate
            hibernate-entitymanager
            3.3.1.ga
            
                
                    commons-logging
                    commons-logging
                
            
        
        
            org.hibernate
            hibernate-core
            3.3.0.CR2
        
        
            org.hibernate
            hibernate-ehcache
            3.3.0.CR2
            
                
                    jboss-logging
                    org.jboss.logging
                
                
                    commons-logging
                    commons-logging
                
            
        
        
            c3p0
            c3p0
            0.9.1.1
        
        
            antlr
            antlr
            2.7.7
        
        
            aopalliance
            aopalliance
            1.0
        
        
            javax.servlet
            javax.servlet-api
            3.0.1
        
        
            stax
            stax-api
            1.0.1
        
        
            org.apache.axis2
            axis2-kernel
            1.6.1
            
                
                    servlet-api
                    javax.servlet
                
            
        
        
            org.apache.ws.commons.axiom
            axiom-api
            1.2.12
            
                
                    commons-logging
                    commons-logging
                
            
        
        
            org.apache.geronimo.specs
            geronimo-activation_1.1_spec
            1.0.2
        
        
            org.apache.geronimo.specs
            geronimo-javamail_1.4_spec
            1.6
        
        
            jaxen
            jaxen
            1.1.1
            
                
                    xercesImpl
                    xerces
                
                
                    xml-apis
                    xml-apis
                
                
                    xmlParserAPIs
                    xerces
                
            
         
        
            org.apache.geronimo.specs
            geronimo-stax-api_1.0_spec
            1.0.1
        
        
            org.apache.geronimo.specs
            geronimo-ws-metadata_2.0_spec
            1.1.2
        
        
            org.apache.ws.commons.axiom
            axiom-impl
            1.2.12
            
                
                    commons-logging
                    commons-logging
                
            
        
        
            org.codehaus.woodstox
            wstx-asl
            3.2.9
        
        
            org.apache.geronimo.specs
            geronimo-jta_1.1_spec
            1.1
        
        
            commons-httpclient
            commons-httpclient
            3.1
            
                
                    commons-logging
                    commons-logging
                
            
        
        
            wsdl4j
            wsdl4j
            1.6.2
        
        
            org.apache.ws.commons.schema
            XmlSchema
            1.4.7
        
        
            org.apache.httpcomponents
            httpcore
            4.0
        
        
            com.javaetmoi.core
            javaetmoi-spring4-vfs2-support
            1.4.0
         
        
            org.springframework
            spring-core
            3.2.13.RELEASE
            
                
                    commons-logging
                    commons-logging
                
            
        
        
            org.springframework
            spring-aop
            3.2.13.RELEASE
        
        
            org.springframework
            spring-tx
            3.2.13.RELEASE
        
        
            org.springframework
            spring-expression
            3.2.13.RELEASE
        
        
            org.springframework.retry
            spring-retry
            1.0.3.RELEASE
        
        
            javax.persistence
            persistence-api
            1.0
        
        
            com.oracle
            ojdbc5
            11.2.0.1
            provided
        
        
            org.slf4j
            slf4j-api
            1.7.11
        
        
            org.slf4j
            slf4j-simple
            1.6.4
        
        
            log4j
            log4j
            1.2.17
        
        
            commons-logging
            commons-logging
            1.1.3
        
        
            logkit
            logkit
            1.0.1
        
        
            org.apache.logging.log4j
            log4j-api
            2.0
        
        
            org.slf4j
            log4j-over-slf4j
            1.7.11
        
        
            org.springframework
            spring-jdbc
            3.2.13.RELEASE
        
        
            com.thoughtworks.xstream
            xstream
            1.4.7
        
        
            org.javassist
            javassist
            3.18.1-GA
        
        
            javax.batch
            javax.batch-api
            1.0
        
        
            org.springframework
            spring-beans
            3.2.13.RELEASE
        
        
            org.springframework
            spring-context
            3.2.13.RELEASE
        
        
            aopalliance
            aopalliance
            1.0
        
        
            javax.ws.rs
            jsr311-api
            1.0
        
        
            org.jboss.logging
            jboss-logging
            3.3.0.Final
        
    
    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.1
                
                    1.6
                    1.6
                
            
            
                org.apache.axis2
                axis2-wsdl2code-maven-plugin
                1.6.2
                
                    
                        
                            wsdl2code
                        
                        
                            true
                            com.globalss.data.processor.service
                            src/main/resources/wsdl/MonitoringService.wsdl
                            xmlbeans
                            sync
                            true
                            true
                            true
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-dependency-plugin
                
                    
                        copy-dependencies
                        package
                        
                            copy-dependencies
                        
                        
                            ${project.build.directory}
                            false
                            true
                        
                    
                
            
        
        
            
                target/generated-sources/axis2/wsdl2code/resources
            
            
                target/generated-sources/xmlbeans/resources
            
            
                src/main/resources
            
            
                src/main/java/com/globalss/dnb/monitor/model/
                com/globalss/dnb/monitor/model/
                
                    *.hbm.xml
                
            
        
    

我尝试了多种解决方法但都没成功。

1st method) 我在 jboss-5.1.0.GA\\lib\\endorsed 文件夹下有这个 jar (xercesImpl)。我将该 jar 删除之后再运行项目。

现在我遇到了以下异常

xception sending context initialized event to listener instance of

class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanDefinitionStoreException:

Unexpected exception parsing XML document from class path resource

[spring-batch-context.xml]; nested exception is

javax.xml.parsers.FactoryConfigurationError: Provider for

javax.xml.parsers.DocumentBuilderFactory cannot be found

2nd) method 我尝试了将以下依赖项从 pom.xml 注释掉

    jaxen
    jaxen
    1.1.1
    
        
            xercesImpl
            xerces
        
        
            xml-apis
            xml-apis
        
        
            xmlParserAPIs
            xerces
        
    
 

但是我得到了相同的异常

org.springframework.beans.factory.BeanDefinitionStoreException:

Unexpected exception parsing XML document from class path resource

[spring-batch-context.xml]; nested exception is

java.lang.ClassCastException:

org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to

javax.xml.parsers.DocumentBuilderFactory at

org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:413)

3rd) Method 我看到一些关于相同问题的解决方案,解决方案是添加以下依赖项

  xerces
  xercesImpl
  2.11.0

在我的 pom.xml 中添加上述依赖项后,我遇到了以下异常

org.jboss.xb.binding.JBossXBRuntimeException: Failed to create a new

SAX parser at

org.jboss.xb.binding.UnmarshallerFactory$UnmarshallerFactoryImpl.newUnmarshaller(UnmarshallerFactory.java:100)

at

org.jboss.web.tomcat.service.deployers.JBossContextConfig.processContextConfig(JBossContextConfig.java:549)

at

org.jboss.web.tomcat.service.deployers.JBossContextConfig.init(JBossContextConfig.java:536)

at

org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:279)

at

org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)

at

org.apache.catalina.core.StandardContext.init(StandardContext.java:5436)

at

org.apache.catalina.core.StandardContext.start(StandardContext.java:4148)

4th) method 我尝试了删除这个 jar \"enter

对我来说也没有用。

我对这个异常感到非常沮丧,但是我无法解决它,

这个链接非常好,它解决了相同的问题,但是我仍然无法解决这个问题。有人能帮我吗?

Dealing with \"Xerces hell\" in Java/Maven?

编辑

我找到了根本原因。

这是从Jboss 5.1运行时的快照。

\"enter

这是来自Maven依赖项的快照。

\"enter

因此,这两个JAR包存在冲突。

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

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

因此,我必须从pom.xml中删除依赖项。

对于(xml-api1.0.b2.jar),我定义了以下依赖项:

    jaxen
    jaxen
    1.1.1
    
        
            xercesImpl
            xerces
        
        
            xml-apis
            xml-apis
        
        
            xmlParserAPIs
            xerces
        
    

但是,当我从pom.xml中注释掉此依赖项时,仍然会在Maven依赖项中获取该jar,如我所示。

我真的不知道(xml-api1.0.b2.jar)是从哪里来的,有人可以通过查看我的pom.xml告诉我吗?

admin 更改状态以发布 2023年5月22日
0
0 Comments

xml-api1.0.b2.jar被poi-3.9引用。
poi-3.9依赖于dom4j,dom4j包含了xml-api1.0.b2。
因此,您可以升级poi至3.16,它将解决这个问题。

0