当前位置 博文首页 > 逐墨飞扬的博客:运行添加spring依赖的项目报错

    逐墨飞扬的博客:运行添加spring依赖的项目报错

    作者:[db:作者] 时间:2021-07-28 11:51

    在运行添加spring依赖的项目时项目会报错,错误信息为下

    1. org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 76; schema_reference.4: 无法读取方案文档 https://www.springframework.org/schema/beans/spring-beans.xsd, 原因为 1) 无法找到文档; 2) 无法读取文档; 3) 文档的根元素不是 <xsd:schema>。
    2. Caused by: java.net.UnknownHostException: www.springframework.org
    3. Exception in thread “main” org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 9 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 76; cvc-elt.1: 找不到元素 ‘beans’ 的声明。
    4. Caused by: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 76; cvc-elt.1: 找不到元素 ‘beans’ 的声明。

    问题分析

    在配置xml文件时文件头配置为

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="
    	        http://www.springframework.org/schema/beans
    	        https://www.springframework.org/schema/beans/spring-beans.xsd">
    </beans>
    

    注意第五行的开头为【https】,此时在运行项目时,会从网上下载项目运行所要依赖的东西(此时不会从本地寻找所需依赖)。当你的电脑没有网无法联网下载,或是有网,但是没有下载成功时,项目运行就会缺少依赖,理所当然的会报错了。

    解决方法

    把配置的xml文件修改为

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

    注意第五行的开头改为以【http】开头了

    cs
    下一篇:没有了