15

I have a web application where i am using spring 3.0 and oracle's XMLTYPE related jar's com.oracle.xdb which in turn depends on com.oracle.xml.xmlparserv2 , iam sure most of you aware of the exception that you get when these jars are used with spring 3.0 as below,

Caused by: oracle.xml.parser.schema.XSDException: Duplicated definition for: 'identifiedType'

there are some suggestions to use a different parser like xerces, but in our case since we use the xdb dependency, it looks like we cannot change it to use another parser other than com.oracle.xml.xmlparserv2, it was working fine with spring 2.5.6 is there any info on when this would be fixed either by spring/oracle?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Aravias
  • 151
  • 1
  • 1
  • 4

6 Answers6

14

Instead of modifying xmlparserv2.jar you can add

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

Click here to read a post on Oracle's forums talking about the issue.

Saikat
  • 14,222
  • 20
  • 104
  • 125
Shane
  • 467
  • 1
  • 4
  • 12
  • Nice one - this resolved my issue. Are there any implications in using the xerces parser instead of the Oracle parser? My application reads XML from an XMLTYPE column on an Oracle DB. – CodeClimber Jul 12 '12 at 15:00
  • I just add xercesImpl package in maven pom.xml, The problem is resolved. – ergoli Feb 18 '17 at 03:34
5

I have identified that the problem is due to the inhability of xmlparserv2 to appropriately parse the xsi:schemaLocation attribute.

I have checked that this works:

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

While this produces the 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"

The workaround is to remove the use of specific namespaces (such as tx, util..) and replace them by the equivalent definitions using common beans. For example, you can replace <tx:annotation-driven/> with <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>

Pau Giner
  • 1,282
  • 11
  • 11
5

Remove /META-INF/services directory from xmlparserv2.jar - it's content registers Oracle's parser.

Marcin Jancewicz
  • 641
  • 7
  • 19
3

Step 4 of my answer here explains why it happens and a few approaches to fixing it.

Community
  • 1
  • 1
Matt M
  • 751
  • 1
  • 9
  • 19
1
  1. Consistent versioning
    schema/beans/spring-beans**-3.1**.xsd schema/jee/spring-jee**-3.1**.xsd schema/mvc/spring-mvc**-3.1**.xsd
    etc.

  2. The order is important. spring-jee-3.1.xsd before spring-beans-3.1.xsd causes error, because in spring-jee-3.1.xsd file we have an import reference to spring-beans-3.1.xsd

lukaszwrzaszcz
  • 170
  • 1
  • 7
  • Looks like my case... But how to debug such inconsistency? I know which is xml file with the 2nd (failed) definition, but how to know where is the first? – Pavel Vlasov Dec 09 '15 at 11:06
  • When you have duplicated definition exception, you can check which XSD contains the definition. Then, you can check imports in previous XSD schemas - just open the schemas and check it. – lukaszwrzaszcz Dec 10 '15 at 11:26
0

If two schemas have an import to the same XSD, you should import that XSD as well to prevent "duplicated definition" error.

For example: I have three schemas:

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

Now I'm getting an errror, because spring-util and spring-jee have an imports to:

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

When spring-tool will be imported manually BEFORE spring-util and 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

the XML configuration will be properly parsed.

Obviously, you should have consistient versions.

Small workaround is to define some part of configuration in other files with described different schemas and import it using:

<import resource="part_of_config.xml"/>
lukaszwrzaszcz
  • 170
  • 1
  • 7