title: Java:Spring: XML conflict on reading spring context.xml Duplicated definition for: 'identifiedType'
body: <p>Any advise or help is much appreciated.</p>
  
  <p>There are many reference links, but there is no clear solution. I wonder how Spring projects interact with PLSQL procedures that returns XMLType output. you would need the XMLParser, and then we all will get this error, when used with Spring. Does anyone has any recommendations?</p>
  
  <p>I have a Maven spring app(mvc/Rest) which is running good, and I added the below dependencies for interacting with the PLSQL procedures,</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;com.oracle&lt;/groupId&gt;
          &lt;artifactId&gt;ojdbc6&lt;/artifactId&gt;
          &lt;version&gt;11.2.0.4&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.oracle&lt;/groupId&gt;
          &lt;artifactId&gt;xdb6&lt;/artifactId&gt;
          &lt;version&gt;11.2.0.4&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.xmlparserv2&lt;/groupId&gt;
          &lt;artifactId&gt;xmlparserv2&lt;/artifactId&gt;
          &lt;version&gt;11.1.1&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>After including <code>xdb6</code> and <code>xmlparserv2</code>, I get the below error on Spring application startup(while running the server)</p>
  
  <p>2014-08-19 18:28:51,898  INFO | main | o.s.beans.factory.xml.XmlBeanDefinitionReader       </p>
  
  <pre><code>Loading XML bean definitions from class path resource [META-INF/spring/myapp-context.xml] 
  
  
  &lt;Line 43, Column 57&gt;: XML-24509: (Error) Duplicated definition for: 'identifiedType'
  &lt;Line 60, Column 28&gt;: XML-24509: (Error) Duplicated definition for: 'beans'
  &lt;Line 140, Column 34&gt;: XML-24509: (Error) Duplicated definition for: 'description'
  &lt;Line 152, Column 29&gt;: XML-24509: (Error) Duplicated definition for: 'import'
  &lt;Line 174, Column 28&gt;: XML-24509: (Error) Duplicated definition for: 'alias'
  &lt;Line 203, Column 33&gt;: XML-24509: (Error) Duplicated definition for: 'beanElements'
  &lt;Line 218, Column 44&gt;: XML-24509: (Error) Duplicated definition for: 'beanAttributes'
  &lt;Line 462, Column 43&gt;: XML-24509: (Error) Duplicated definition for: 'meta'
  &lt;Line 470, Column 35&gt;: XML-24509: (Error) Duplicated definition for: 'metaType'
  &lt;Line 487, Column 27&gt;: XML-24509: (Error) Duplicated definition for: 'bean'
  &lt;Line 507, Column 38&gt;: XML-24509: (Error) Duplicated definition for: 'constructor-arg'
  .....
  
  2014-08-19 18:28:52,014 ERROR | main | org.springframework.web.servlet.DispatcherServlet       | Context initialization failed 
  org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 16 in XML document from class path resource [META-INF/spring/myapp-context.xml] is invalid; nested exception is oracle.xml.parser.schema.XSDException: Duplicated definition for: 'identifiedType'
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
  </code></pre>
  
  <p>Line 16 in XML document from class path resource [META-INF/spring/myapp-context.xml] is invalid;</p>
  
  <p><strong>myapp-context.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:sec="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
      xmlns:cache="http://www.springframework.org/schema/cache"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd  
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/security
          http://www.springframework.org/schema/security/spring-security-3.1.xsd
          http://www.springframework.org/schema/util
          http://www.springframework.org/schema/util/spring-util-3.2.xsd
          http://www.springframework.org/schema/cache 
          http://www.springframework.org/schema/cache/spring-cache.xsd"&gt;
  </code></pre>
  
  <p>Line16 is  <code>http://www.springframework.org/schema/cache/spring-cache.xsd"&gt;</code></p>
  
  <p>Suppose I remove Line16 and its references, then the same error is thrown at a different line, say Line 13</p>
  
  <p>More error stack trace:</p>
  
  <pre><code>Caused by: org.xml.sax.SAXParseException: &lt;Line 13, Column 70&gt;: XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/tx' located at 'http://www.springframework.org/schema/tx/spring-tx.xsd'
      at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:425) ~[xmlparserv2-11.1.1.jar:na]
      at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:287) ~[xmlparserv2-11.1.1.jar:na]
      at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:343) ~[xmlparserv2-11.1.1.jar:na]
      at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:226) ~[xmlparserv2-11.1.1.jar:na]
      at oracle.xml.jaxp.JXDocumentBuilder.parse(JXDocumentBuilder.java:155) ~[xmlparserv2-11.1.1.jar:na]
  
  
  Caused by: oracle.xml.parser.schema.XSDException: Duplicated definition for: 'identifiedType'
      at oracle.xml.parser.schema.XSDBuilder.buildSchema(XSDBuilder.java:794) ~[xmlparserv2-11.1.1.jar:na]
      at oracle.xml.parser.schema.XSDBuilder.build(XSDBuilder.java:489) ~[xmlparserv2-11.1.1.jar:na]
      at oracle.xml.parser.schema.XSDValidator.processSchemaLocation(XSDValidator.java:999) ~[xmlparserv2-11.1.1.jar:na]
      at oracle.xml.parser.schema.XSDValidator.startElement(XSDValidator.java:604) ~[xmlparserv2-11.1.1.jar:na]
  </code></pre>
  
  <p><strong>Update 1</strong></p>
  
  <p>Based on the posted answer, it says a quick solution is available,</p>
  
  <p>To override the changes made by xmlparserv2.jar, add the following JVM properties to your application server startup arguments.  The java.xml.parsers.FactoryFinder logic will check environment variables first.</p>
  
  <pre><code>-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
  
   -Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
  
   -Djavax.xml.transform.TransformerFactory=com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
  </code></pre>
  
  <p>This is not recommended, as clearly stated in the link
  <a href="https://community.oracle.com/thread/1080787" rel="nofollow noreferrer">https://community.oracle.com/thread/1080787</a></p>
  
  <p>Another solution is mentioned here (related to hibernate, but similar): <a href="https://stackoverflow.com/questions/11578697/using-oracle-xmltype-column-in-hibernate/18282094#18282094">Using Oracle XMLType column in hibernate</a></p>
  
  <p>In a maven spring project, override the xmlparserv2.jar settings by creating the following files in the %PROJECT_HOME%/src/main/resources directory:</p>
  
  <pre><code>%PROJECT_HOME%/src/main/resources/META-INF/services/javax.xml.parsers.DocumentBuilderFactory (which defines com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl as the default)
  %PROJECT_HOME%/src/main/resources/META-INF/services/javax.xml.parsers.SAXParserFactory (which defines com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl as the default)
  %PROJECT_HOME%/src/main/resources/META-INF/services/javax.xml.transform.TransformerFactory (which defines com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl as the default)
  </code></pre>
  
  <p>This is not clear to me. </p>
  
  <p>How to drop these files to the mentioned directory? and is that a recommended solution?</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>I tried adding the VM argument <code>-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl</code>  and it works.</p>
  
  <p>However looking for an alternate, and more appropriate solution. This is just a workaround. When the application is deployed to server via say Jenkins, its not proper to set these VM argument settings related to a XML parser.</p>
  
  <p><strong>Update 3</strong></p>
  
  <p>@Ian Roberts's answer fixed the issue. I cleaned up the context.xml to use version number for the xsd consistently.</p>