您的schemaLocation是版本(spring-beans-3.2.xsd)和非版本(spring-tx.xsd)模式名称的混合。您应始终使用一种样式或另一种样式,而不要混合使用两种样式。我怀疑这里发生的事情是您明确引用了3.2版本的spring-beans,但是您的未版本化架构中的一个导入了相同架构的另一个版本,导致的两个定义冲突beans:identifiedType。
解决方法任何建议或帮助,我们将不胜感激。
参考链接很多,但是没有明确的解决方案。我想知道Spring项目如何与返回XMLType输出的PLSQL过程交互。您将需要XMLParser,然后与Spring一起使用时,我们所有人都会收到此错误。有人有什么建议吗?
我有一个运行良好的Maven spring应用程序(mvc / Rest),并且添加了以下与PLSQL过程进行交互的依赖项,
<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>
包含xdb6和之后xmlparserv2,在Spring应用程序启动时(运行服务器时)出现以下错误
2014-08-19 18:28:51,898信息| 主| 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]
来自类路径资源[META-INF / spring / myapp-context.xml]的XML文档中的第16行无效;
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.xsdhttp://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.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/securityhttp://www.springframework.org/schema/security/spring-security-3.1.xsdhttp://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-3.2.xsdhttp://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行
更多错误堆栈跟踪:
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
根据发布的答案,它说有一个快速的解决方案,
要覆盖xmlparserv2.jar所做的更改,请将以下JVM属性添加到应用程序服务器启动参数中。java.xml.parsers.FactoryFinder逻辑将首先检查环境变量。
-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中明确指出的那样,不建议这样做
在Maven Spring项目中,通过在%PROJECT_HOME%/ src / main /resources目录中创建以下文件来覆盖xmlparserv2.jar设置:
%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)
我不清楚。
如何将这些文件拖放到提到的目录中?这是推荐的解决方案吗?
更新2
我尝试添加VM参数-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl,它有效。
但是,寻找替代的,更合适的解决方案。这只是一个解决方法。当通过说Jenkins将应用程序部署到服务器时,不适合设置这些与XML解析器相关的VM参数设置。
更新3
@Ian Roberts的答案解决了这个问题。我清理了context.xml以一致地使用xsd的版本号。