【问题标题】:Duplicated definition for: 'identifiedType'重复定义:'identifiedType'
【发布时间】:2011-06-27 17:08:23
【问题描述】:

我有一个 web 应用程序,我在其中使用 spring 3.0 和 oracle 的 XMLTYPE 相关 jar 的 com.oracle.xdb ,这又取决于 com.oracle.xml.xmlparserv2 ,我相信你们中的大多数人都知道你在什么时候得到的异常这些罐子与 spring 3.0 一起使用,如下所示,

原因:oracle.xml.parser.schema.XSDException:重复定义:'identifiedType'

有一些建议可以使用像 xerces 这样的不同解析器,但在我们的例子中,由于我们使用 xdb 依赖项,看起来我们无法将其更改为使用 com.oracle.xml.xmlparserv2 以外的其他解析器,它正在工作spring 2.5.6 很好,是否有任何关于 spring/oracle 何时修复此问题的信息?

【问题讨论】:

    标签: xml oracle spring types jar


    【解决方案1】:

    您可以添加而不是修改xmlparserv2.jar

    -Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

    Click here 阅读 Oracle 论坛上讨论该问题的帖子。

    【讨论】:

    • 不错 - 这解决了我的问题。使用 xerces 解析器而不是 Oracle 解析器有什么影响吗?我的应用程序从 Oracle DB 上的 XMLTYPE 列中读取 XML。
    • 我只是在maven pom.xml中添加了xercesImpl包,问题解决了。
    【解决方案2】:

    我发现问题是由于 xmlparserv2 无法正确解析 xsi:schemaLocation 属性。

    我已经检查过它是否有效:

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
    

    虽然这会产生错误:

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
    

    解决方法是删除对特定命名空间(例如 tx、util..)的使用,并将它们替换为使用公共 bean 的等效定义。例如,您可以将<tx:annotation-driven/> 替换为<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>

    【讨论】:

      【解决方案3】:

      从 xmlparserv2.jar 中删除 /META-INF/services 目录 - 它的内容注册了 Oracle 的解析器。

      【讨论】:

        【解决方案4】:
        my answer here

        第 4 步解释了它发生的原因以及修复它的一些方法。

        【讨论】:

          【解决方案5】:
          1. 一致的版本控制
            schema/beans/spring-beans**-3.1**.xsd schema/jee/spring-jee**-3.1**.xsd schema/mvc/spring-mvc**-3.1**.xsd
            等等。

          2. 顺序很重要。 spring-jee-3.1.xsdspring-beans-3.1.xsd 之前会导致错误,因为在 spring-jee-3.1.xsd 文件中我们有一个对 spring- 的导入引用beans-3.1.xsd

          【讨论】:

          • 看起来像我的情况...但是如何调试这种不一致?我知道哪个是带有第二个(失败)定义的 xml 文件,但如何知道第一个定义在哪里?
          • 当您有重复定义异常时,您可以检查哪个 XSD 包含该定义。然后,您可以检查以前 XSD 模式中的导入 - 只需打开模式并检查它。
          【解决方案6】:

          如果两个架构都导入到同一个 XSD,您也应该导入该 XSD 以防止出现“重复定义”错误。

          例如: 我有三个架构:

          http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
          http://www.springframework.org/schema/util/spring-util-4.2.xsd
          http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
          

          现在我遇到了一个错误,因为 spring-util 和 spring-jee 有一个导入到:

          <xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans-4.2.xsd"/>
          <xsd:import namespace="http://www.springframework.org/schema/tool" schemaLocation="http://www.springframework.org/schema/tool/spring-tool-4.2.xsd"/>
          

          在 spring-util 和 spring-jee 之前手动导入 spring-tool 时:

          http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
          http://www.springframework.org/schema/tool/spring-tool-4.2.xsd
          http://www.springframework.org/schema/util/spring-util-4.2.xsd
          http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
          

          XML 配置将被正确解析。

          显然,您应该有一致的版本。

          小解决方法是在其他文件中使用描述的不同架构定义配置的某些部分,并使用以下方法导入:

          <import resource="part_of_config.xml"/>
          

          【讨论】:

            猜你喜欢
            • 2014-10-13
            • 2021-12-26
            • 2011-08-29
            • 1970-01-01
            • 2019-08-05
            • 1970-01-01
            • 2012-10-13
            • 1970-01-01
            • 2012-02-07
            相关资源
            最近更新 更多