无法读取方案文档 'http://www.springframework.org/schema/beans/spring-beans-4.1.xsd'问题解决

起因:
前一分钟还在欢快的调试着项目,下一秒钟启动项目的时候突然抛出以下异常,项目启动失败,先看错误信息:

无法读取方案文档 'http://www.springframework.org/schema/beans/spring-beans-4.1.xsd', 
原因为 1) 无法找到文档; 2) 无法读取文档; 3) 文档的根元素不是 <xsd:schema>

出现问题当然先百度谷歌,得出的原因是,spring官网有时候会抽疯无法访问上或者你的网络很差连不上http://www.springframework.org/schema/beans/spring-beans-4.1.xsd这个地址,总之你打不开这个链接地址,你的项目就嗝屁了。

纳尼!怎么能这样受制于人呢?于是开始搜寻解决方案,终于找到一个靠谱的说法,就是让项目加载本地的spring-beans-x.x.xsd文件从而摆脱对网络请求的限制。先看本地配置文件详细内容:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:context="http://www.springframework.org/schema/context" xmlns:jms="http://www.springframework.org/schema/jms" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd

我本地解决方案就是将http://www.springframework.org/schema/beans/spring-beans-4.1.xsd 替换为 classpath:/org/springframework/beans/factory/xml/spring-beans-2.0.xsd 当然你们会疑问为什么替换为 spring-beans-2.0.xsd版本而不是别的版本呢,在开发工具中(我用的是idea)使用ctrl + 左键选中http://www.springframework.org/schema/beans/spring-beans-4.1.xsd 跳转至文件就是 classpath:/org/springframework/beans/factory/xml/spring-beans-2.0.xsd 其他版本的xsd我还没试过,感兴趣的同学可以尝试下;替换完成后,直接启动就不会再出现之前那个烦人的错误信息了,又可以欢快的调试项目了。

0927项目完结:现在回头看看上面写的内容,觉得自己当时是真的蠢,上面做法的问题是批量更改麻烦不说,还会报classpath语法错误。
其实当时仔细看日志信息,就不会有上面的做法;

Trying to resolve XML entity with public id [null] and system id [http://www.springframework.org/schema/beans/spring-beans-3.2.xsd]
Found XML schema [http://www.springframework.org/schema/beans/spring-beans-3.2.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-3.2.xsd
Trying to resolve XML entity with public id [null] and system id [http://www.springframework.org/schema/context/spring-context-3.2.xsd]
Found XML schema [http://www.springframework.org/schema/context/spring-context-3.2.xsd] in classpath: org/springframework/context/config/spring-context-3.2.xsd
Trying to resolve XML entity with public id [null] and system id [http://www.springframework.org/schema/tool/spring-tool-3.2.xsd]
Found XML schema [http://www.springframework.org/schema/tool/spring-tool-3.2.xsd] in classpath: org/springframework/beans/factory/xml/spring-tool-3.2.xsd

以上是项目启动加载信息,说明项目启动时会自动加载本地xsd文件,出现以上问题是因为,我配置的是4.1.xsd版本的文件本地最高只能支持3.2.xsd版本文件,网速好的时候通过http请求到xsd文件。然而网速不好的时候本地无法支持高版本的xsd文件,就只会出报错信息,项目启动失败。
由以上分析得出两种解决方案,一种是升级高版本的jar包其中包含高版本的xsd文件,其二是降低配置的xsd文件版本使本地jar能够满足。最后一句话让本地jar满足配置的xsd版本就不会出现异常信息。

猜你喜欢

转载自blog.csdn.net/fu250/article/details/78043901