Java: Spring: XML conflict while reading spring context.xml Duplicate definition for: 'identType'

Any advice or help is greatly appreciated.

There are many links, but no clear solution. I wonder how Spring projects interact with PLSQL procedures that return XMLType output. you need XMLParser, and then we all get this error when used with Spring. Does anyone have any recommendations?

I have a Maven Spring application (mvc / Rest) that works well, and I added the following dependencies to interact with PLSQL procedures,

<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.4</version> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>xdb6</artifactId> <version>11.2.0.4</version> </dependency> <dependency> <groupId>com.xmlparserv2</groupId> <artifactId>xmlparserv2</artifactId> <version>11.1.1</version> </dependency> 

After enabling xdb6 and xmlparserv2 I get the following error when starting the Spring application (when starting the server)

2014-08-19 18: 28: 51,898 INFO | home | osbeans.factory.xml.XmlBeanDefinitionReader

 Loading XML bean definitions from class path resource [META-INF/spring/myapp-context.xml] <Line 43, Column 57>: XML-24509: (Error) Duplicated definition for: 'identifiedType' <Line 60, Column 28>: XML-24509: (Error) Duplicated definition for: 'beans' <Line 140, Column 34>: XML-24509: (Error) Duplicated definition for: 'description' <Line 152, Column 29>: XML-24509: (Error) Duplicated definition for: 'import' <Line 174, Column 28>: XML-24509: (Error) Duplicated definition for: 'alias' <Line 203, Column 33>: XML-24509: (Error) Duplicated definition for: 'beanElements' <Line 218, Column 44>: XML-24509: (Error) Duplicated definition for: 'beanAttributes' <Line 462, Column 43>: XML-24509: (Error) Duplicated definition for: 'meta' <Line 470, Column 35>: XML-24509: (Error) Duplicated definition for: 'metaType' <Line 487, Column 27>: XML-24509: (Error) Duplicated definition for: 'bean' <Line 507, Column 38>: 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] 

Line 16 in the XML document from the class path resource [META-INF / spring / myapp-context.xml] is invalid;

Myapp-context.xml

 <?xml version="1.0" encoding="UTF-8"?> <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"> 

Line 16 - http://www.springframework.org/schema/cache/spring-cache.xsd">

Suppose that I delete Line16 and its links, then the same error occurs on another line, for example, line 13

More error stack trace:

 Caused by: org.xml.sax.SAXParseException: <Line 13, Column 70>: 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] 

Update 1

Based on the answer, he says a quick solution is available,

To override the changes made using xmlparserv2.jar, add the following JVM properties to the startup arguments of your application server. The logic java.xml.parsers.FactoryFinder will first check the environment variables.

 -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 

This is not recommended, as clearly indicated in the link https://community.oracle.com/thread/1080787

Here's another solution mentioned (related to hibernation but similar): Using an Oracle XMLType column in hibernation

In the maven Spring project, override the xmlparserv2.jar parameters by creating the following files in the% PROJECT_HOME% / src / main / resources directory:

 %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) 

I don’t understand this.

How to transfer these files to the specified directory? and is this a recommended solution?

Update 2

I tried adding the VM argument -Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl and it works.

However, the search for an alternative and more suitable solution. This is just a workaround. When an application is deployed to a server using Jenkins, it is impractical to set these VM argument parameters associated with the XML parser.

Update 3

@ Ying Roberts responded to fix the problem. I cleaned up context.xml to consistently use the version number for xsd.

+5
source share
3 answers

The schemaLocation scheme is a mixture of version versions ( spring-beans-3.2.xsd ) and unversioned ( spring-tx.xsd ) schemes. You should use one style or the other in series, and not mix them. I suspect that what is happening here is that you are explicitly referencing version 3.2 of spring - beans, but one of your unversioned schemas imports another version of the same schema, resulting in two conflicting definitions of beans:identifiedType .

+4
source

This article is quite old, but in any case, I came across this today and found a reason and another solution. It turns out that when you add the jazbc oracle driver dependency through maven using the Oracle maven repo, it transits other libraries that cause this problem when parsing XML. I just ruled out transitive dependencies for the oracle driver, and everything works fine. I do not think that these additional libraries are necessary at all at runtime.

If you have this in your pom:

 <dependency> <groupId>com.oracle.jdbc</groupId> <artifactId>ojdbc7</artifactId> <version>12.1.0.2</version> </dependency> 

This is a dependency tree:

  • ojdbc7: 12.1.0.2
    • xdb6: 12.1.0.2
    • orai18n: 12.1.0.2
    • xmlparserv2: 12.1.0.2 <- Culprit
    • oraclepki: 12.1.0.2
    • osdt_cert: 12.1.0.2
    • osdt_core: 12.1.0.2

Thus, you can exclude such an abusive library:

 <dependency> <groupId>com.oracle.jdbc</groupId> <artifactId>ojdbc7</artifactId> <version>12.1.0.2</version> <exclusions> <exclusion> <artifactId>xmlparserv2</artifactId> <groupId>com.oracle.jdbc</groupId> </exclusion> </exclusions> </dependency> 

I actually ruled out all the transitive dependencies, and everything seems to be working fine. I am not sure if they are really used. I don’t think so, because the manual way to enable the jdbc library is to simply load the ojdbc banner.

+7
source

Here is your decision.

 -Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl` 
+6
source

Source: https://habr.com/ru/post/1200707/


All Articles