Java:Spring:读取spring context.xml时XML冲突 [英] Java:Spring: XML conflict on reading spring context.xml Duplicated definition for: 'identifiedType'

查看:251
本文介绍了Java:Spring:读取spring context.xml时XML冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何建议或帮助都将不胜感激.

Any advise or help is much appreciated.

有许多参考链接,但是没有明确的解决方案.我想知道Spring项目如何与返回XMLType输出的PLSQL过程交互.您将需要XMLParser,然后与Spring一起使用时,我们所有人都会收到此错误.有人有什么建议吗?

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?

我有一个运行良好的Maven spring应用程序(mvc/Rest),我添加了以下与PLSQL过程进行交互的依赖项,

I have a Maven spring app(mvc/Rest) which is running good, and I added the below dependencies for interacting with the 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>

在包含xdb6xmlparserv2之后,在Spring应用程序启动时(运行服务器时)出现以下错误

After including xdb6 and xmlparserv2, I get the below error on Spring application startup(while running the server)

2014-08-19 18:28:51,898信息|主| o.s.beans.factory.xml.XmlBeanDefinitionReader

2014-08-19 18:28:51,898 INFO | main | o.s.beans.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]

来自类路径资源[META-INF/spring/myapp-context.xml]的XML文档中的第16行无效;

Line 16 in XML document from 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">

第16行是http://www.springframework.org/schema/cache/spring-cache.xsd">

假设我删除Line16及其引用,然后在另一行(例如第13行)抛出相同的错误

Suppose I remove Line16 and its references, then the same error is thrown at a different line, say Line 13

更多错误堆栈跟踪:

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]

更新1

根据发布的答案,它说有一个快速的解决方案,

Based on the posted answer, it says a quick solution is available,

要覆盖xmlparserv2.jar所做的更改,请在应用程序服务器启动参数中添加以下JVM属性. java.xml.parsers.FactoryFinder逻辑将首先检查环境变量.

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.

-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

不建议这样做,正如链接中明确指出的那样 https://community.oracle.com/thread/1080787

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

此处提到了另一个解决方案(与休眠有关,但类似):在休眠状态下使用Oracle XMLType列

Another solution is mentioned here (related to hibernate, but similar): Using Oracle XMLType column in hibernate

在maven spring项目中,通过在%PROJECT_HOME%/src/main/resources目录中创建以下文件来覆盖xmlparserv2.jar设置:

In a maven spring project, override the xmlparserv2.jar settings 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)

我不清楚.

如何将这些文件拖放到提到的目录中?这是推荐的解决方案吗?

How to drop these files to the mentioned directory? and is that a recommended solution?

更新2

我尝试添加VM参数-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl,它有效.

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

但是,正在寻找其他更合适的解决方案.这只是一个解决方法.当通过说Jenkins将应用程序部署到服务器时,不适合设置这些与XML解析器相关的VM参数设置.

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.

更新3

@Ian Roberts的答案解决了该问题.我清理了context.xml以始终使用xsd的版本号.

@Ian Roberts's answer fixed the issue. I cleaned up the context.xml to use version number for the xsd consistently.

推荐答案

您的schemaLocation是版本(spring-beans-3.2.xsd)和未版本化(spring-tx.xsd)模式名称的混合.您应始终使用一种样式或另一种样式,而不要混合使用两种样式.我怀疑这里发生的事情是您明确引用了3.2版本的spring-beans,但是您的未版本化架构中的一个导入了同一架构的另一个版本,从而导致beans:identifiedType的两个冲突定义.

Your schemaLocation is a mixture of versioned (spring-beans-3.2.xsd) and unversioned (spring-tx.xsd) schema names. You should use one style or the other consistently rather than mixing the two. I suspect what's happening here is that you're explicitly referring to version 3.2 of spring-beans but one of your unversioned schemas imports a different version of the same schema, resulting in two conflicting definitions of beans:identifiedType.

这篇关于Java:Spring:读取spring context.xml时XML冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆