惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
量子位
腾讯CDC
A
About on SuperTechFans
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
T
Tailwind CSS Blog
V
V2EX
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
Recent Announcements
Recent Announcements
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
罗磊的独立博客
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
V
Visual Studio Blog
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
有赞技术团队
有赞技术团队

博客园 - zbjice

mybatis-plus saveBatch方法java.lang.NullPointerException MacOS打开应用后反复提示“XXX将对你的电脑造成伤害。你应该将它移到废纸篓”的解决办法 charles代理证书更新 cron表达式里日期和星期关系 oracle设置与数据源的 JDBC 连接 JDK升级问题记录 图片压缩优化 APP中https证书有效性验证引发安全问题(例Fiddler可抓https包) Fullgc引发redis超时异常 maven父子模块deploy 问题 lua post参数获取,参数截断 PhpStorm, XDebug, and DBGp Proxy Dia Diagram Mac OSX Yosemite Fix 闪退 xterm sql优化-隐形转换危害 mybatis 关联映射传递多参数方法 分页栏页码输入框校验 oracle中查询或插入特殊字符 使用a标签或form的submit做下载按钮,然后通过js调用其click事件去下载时经常出现的异常 eclipse、tomcat搭建时出现异常
加载spring的xsd文件失败,导致发布失败
zbjice · 2022-05-31 · via 博客园 - zbjice

1.事故现象

某个项目在发布生产的失败,回滚以前tag同样发布失败,错误信息,如下

rg.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans-3.2.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) ~[?:1.6.0_45]
......
[ERROR][20-03-04 15:34:45,197]-traceId:[]ContextLoader:308-Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [dubbo-common.xml]
Offending resource: class path resource [application.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 5 in XML document from class path resource [dubbo-common.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) ~[spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
...
详细错误见发布平台启动日志

2.事故原因

首先需要了解xsd文件加载的过程,spring在加载xsd文件时总是先试图在本地查找xsd文件(spring的jar包中已经包含了所有版本的xsd文件),如果没有找到,才会转向去URL指定的路径下载。在很多spring的jar包里,在META-INF目录下都有一个spring.schemas,这个文件就是spring关于xsd文件在本地存放路径的映射,spring就是通过这个文件在本地(也就是spring的jar里)查找xsd文件的。那么,查找不到的原因排除URL输入有误之外,可能就是声明的xsd文件版本在本地不存在。一般来说,新版本的spring jar包会将过去所有版本(应该是自2.0以后)的xsd打包,并在spring.schemas文件中加入了对应项,出现问题的情况往往是声明使用了一个高版本的xsd文件,如3.0,但依赖缺失低版本的spring的jar包,此时就会导致spring去站点下载目标xsd文件,如遇断网或是目标站点不可用,上述问题就发生了。

本图中,通过点击连接,会跳转到本地的xsd文件。

经排查secooCrm中使用的是“http://www.springframework.org/schema/beans/spring-beans-3.2.xsd“,而j项目中使用的版本为spring-xx-3.1.1,程序加载时,无法在本地的jar中找到spring-beans-3.2.xsd,所以只能从spring官网进行下载。