2011-02-15 61 views
14

我有一個web應用程序,我使用spring 3.0和oracle的XMLTYPE相關的jar的com.oracle.xdb,而這又取決於com.oracle.xml.xmlparserv2,我相信大多數人知道當這些罐子彈簧3.0如下用你得到的異常的重複的定義:'identifiedType'

造成的:oracle.xml.parser.schema.XSDException:重複的定義:「identifiedType」

有是一些建議使用不同的分析器,如xerces,但在我們的情況,因爲我們使用xdb依賴,它看起來像我們不能改變它使用除了com.oracle.xml.xmlparserv2之外的另一個解析器,它在2.5.6的spring中工作正常嗎?有沒有關於spring何時可以修復的信息?

回答

5

我已經確定問題是由於xmlparserv2的可吸入性,以適當解析xsi:schemaLocation屬性。

我已檢查,這種工作的:

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

雖然這產生eror:

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 class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>

+0

這並沒有爲我工作:( – saikosen 2017-03-25 13:32:10

5

從xmlparserv2.jar中刪除/ META-INF/services目錄 - 它的內容註冊Oracle的解析器。

13

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

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

Click here閱讀Oracle的論壇上談到這一問題的帖子。

+0

尼斯一個 - 這解決了我的問題是否有在使用xerces分析器而不是Oracle分析器的任何影響?我的應用程序從Oracle數據庫的XMLTYPE列中讀取XML – CodeClimber 2012-07-12 15:00:05

+0

我只需在maven pom.xml中添加xercesImpl軟件包,問題就解決了。 – ergoli 2017-02-18 03:34:48

3

第4步my answer here解釋了爲什麼會發生,並解決它的幾種方法。

1
  1. 一致的版本
    schema/beans/spring-beans**-3.1**.xsd schema/jee/spring-jee**-3.1**.xsd schema/mvc/spring-mvc**-3.1**.xsd

  2. 的順序很重要。 彈簧JEE-3.1.xsd彈簧豆-3.1.xsd導致錯誤,因爲在彈簧JEE-3.1.xsd文件中,我們有一個進口參考春天的bean-3.1.xsd

0

如果模式對同一個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 

現在我得到一個errror,因爲彈簧UTIL和彈簧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"/> 

春天-tool將手動導入在spring-util和spring-jee之前:

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"/>