我最近将代码从 spring 4 (4.1.7) 迁移到 spring 5(5.1.4)。
在这个春季迁移期间,我从项目 spring Xmls 中删除了版本号,这是我无法更新的库中的 xml 架构:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd"
default-lazy-init="true"
>
升级后由于我上面给出的库 XML 在加载 bean 定义时低于异常:
引起:org.xml.sax.SAXParseException;行号:XX;列号:XX;:XML-24500:(错误)无法构建位于“http://www.springframework.org/schema/context/spring-context-3.1”的架构“ http://www.springframework.org/schema/context ” 。 xsd '
详细的堆栈跟踪是:
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 16 in XML document from class path resource [xxxlib-core-spring-main.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 5; <Line 16, Column 5>: XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/context' located at 'http://www.springframework.org/schema/context/spring-context-3.1.xsd'
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:622)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:518)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:95)
at com.xxxxxxxx.dataaccess.xxx.util.SpringHelper.init(SpringHelper.java:41)
at com.xxxxxxxx.dataaccess.xxx.util.SpringHelper.getBean(SpringHelper.java:69)
at com.xxxxxxxx.dataaccess.xxx.api.xxxAPILoader.<clinit>(xxxAPILoader.java:339)
... 30 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 5; <Line 16, Column 5>: XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/context' located at 'http://www.springframework.org/schema/context/spring-context-3.1.xsd'
at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:428)
at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:290)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:425)
at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:242)
at oracle.xml.jaxp.JXDocumentBuilder.parse(JXDocumentBuilder.java:175)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:77)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:434)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
... 46 more
Caused by: oracle.xml.parser.schema.XSDException: Duplicated definition for: 'identifiedType'
at oracle.xml.parser.schema.XSDBuilder.buildSchema(XSDBuilder.java:1122)
at oracle.xml.parser.schema.XSDBuilder.build(XSDBuilder.java:673)
at oracle.xml.parser.schema.XSDValidator.processSchemaLocation(XSDValidator.java:1063)
at oracle.xml.parser.schema.XSDValidator.startElement(XSDValidator.java:668)
at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1635)
at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:458)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:404)
- 这是否意味着只有当我们所有的库都在 spring 5 上时我们才能迁移到 Spring 5 ?(我不敢相信春天会引入这样的问题)
- 有没有解决这个问题的方法?
- 我是否因为得到这个异常而错过了一些配置
我遇到了github-issue,它建议在 spring 5 中删除版本,但仍然支持旧版本。
编辑1:
我遇到了另一个问题:,因为在使用以下解决方法(看起来像)之后我也在使用 xmlparserv2-12.1.0.2.jar 它似乎通过了这个异常(XSDException:重复定义:'identifiedType')但仍然无法加载来自库的 bean,现在它抛出异常 org.springframework.beans.factory.NoSuchBeanDefinitionException
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
编辑2:
以上Edit1解决了我的问题,bean异常是我的本地设置问题。我遇到了另一个很好的答案,它说我们不能混合未版本化和版本化的模式。但就我而言,我无法从第三方库中删除版本号,在这种情况下,我将不得不通过 Edit1 中给出的解决方案,尽管这看起来很糟糕。
有没有其他更好的方法来解决这个问题?