【问题标题】:org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 122; cvc-elt.1: Cannot find the declaration of element 'beans'org.xml.sax.SAXParseException;行号:6;列号:122; cvc-elt.1:找不到元素“beans”的声明
【发布时间】:2015-08-11 23:04:43
【问题描述】:

我正在使用 spring,但遇到了问题

我的servlet-config.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:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://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.xsd">

    <mvc:annotation-driven/>
        <context:component-scan base-package="somepackage"/>
            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
     <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
    </beans>

例外

org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 122; cvc-elt.1: Cannot find the declaration of element 'beans'.

第 6 行是http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"&gt;

我已经搜索了很多类似的问题并尝试了它们,但效果很好。

我已经检查了我的互联网连接,还尝试通过删除版本号来转换网址,但仍然有效。

我不想下载并在本地存储这些 xsd 文件,但如果我的连接正常,为什么我会遇到这个问题,我也尝试清理 eclipse 缓存

谁能帮帮我?

@Jens 之后我的项目工作了,但 IDE 显示如下所示的一些错误

在这一行发现多个注释:

  • schema_reference.4:无法读取架构文档“http://www.springframework.org/schema/context/spring-context.xsd”,
    因为 1) 找不到文件; 2) 文件不能
    被阅读; 3) 文档的根元素不是。
  • cvc-complex-type.2.4.c:匹配通配符是严格的,但找不到元素“context:component-scan”的声明。

【问题讨论】:

    标签: java xml spring spring-mvc xsd


    【解决方案1】:

    您忘记了 bean 的 scemaLocation:

     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    

    我建议您删除 xsd 的版本。迁移到其他版本更容易

    【讨论】:

    • @codegasmer 你能重新验证文件吗?它与其他答案相同,所以我对错误感到困惑。
    • @OK 好像是刷新问题
    【解决方案2】:

    将以下行添加到 ** xsi:schemaLocation**

    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    

    然后你的第 6 行将是

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://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.xsd"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-09
      • 2011-10-31
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多