错误:cvc-elt.1:找不到元素'beans'的声明

时间:2018-09-24 19:53:06

标签: java xml spring-mvc servlets xsd

我无法摆脱这个错误:

  

cvc-elt.1:找不到元素'beans'的声明。

我正在Tomcat 9上运行我的Web项目。我已经尝试了stackoverflow上提到的所有方法,但仍然无法处理它。我想这与Spring 5有关。

这是我的代码:

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans"
        xmlns:beans="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        ">

        <bean id="HandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
        <bean name="/welcome.html" class="com.gontuseries.hellocontroller.HelloController"/>
        <bean id="ViewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver">
              <property name="prefix">
                <value>/WEB-INF/</value>
              </property>       
                <property name="suffix">
                <value>.jsp</value>
              </property>   
        </bean> 
</beans>

以下是我得到的例外情况:

Sep 25, 2018 1:15:46 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet [spring-dispatcher]
org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 6; cvc-elt.1: Cannot find the declaration of element 'beans'.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)

1 个答案:

答案 0 :(得分:1)

更改

    xmlns:schemaLocation="

    xsi:schemaLocation="

另请参阅xmlns, xmlns:xsi, xsi:schemaLocation, and targetNamespace?