Spring Grave:上下文初始化失败

Spring Grave:上下文初始化失败,spring,jakarta-ee,spring-mvc,Spring,Jakarta Ee,Spring Mvc,我正在从头开始创建HelloWorld web/spring应用程序。为了学习如何使用mvc模式,我遵循了以下步骤。所以,在完成所有步骤并开始运行应用程序后,我在控制台中收到了以下错误: Grave:上下文初始化失败 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: ServletContext资源的XML文档中的第11行 [/WEB-INF/dispatcher servlet.xml]无效;嵌套异常是

我正在从头开始创建HelloWorld web/spring应用程序。为了学习如何使用mvc模式,我遵循了以下步骤。所以,在完成所有步骤并开始运行应用程序后,我在控制台中收到了以下错误:

Grave:上下文初始化失败 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: ServletContext资源的XML文档中的第11行 [/WEB-INF/dispatcher servlet.xml]无效;嵌套异常是 org.xml.sax.SAXParseException;行号:11;栏目号:100; cvc复合型2.4.c

搜索了这么多问题,我发现了一些威胁,如下所示,但并没有解决我的错误

因此,我推断可能是WEB-INF文件夹中的dispatcher-servlet.xml。此xml看起来像:

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


    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/jsp/</value>
        </property>

        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="interceptors">
            <list>
                <ref local="localeChangeInterceptor" />
            </list>
        </property>

        <property name="urlMap">
            <map>
                <entry key="/hello.html">
                    <ref bean="helloController" />
                </entry>
            </map>
        </property>

    </bean>

    <bean id="helloController" class="controllers.HelloController">
    </bean>

    <bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">

        <property name="paramName" value="hl" />

    </bean>

    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    </bean>

</beans>
提前谢谢

编辑1:

在对@Biju Kunjummen进行更改之后,现在的问题似乎是bean声明中存在comflic:

Grave: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'helloController' while setting bean property 'urlMap' with key [TypedStringValue: value [/hello.html], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloController' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [controllers.HelloController]: Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems: 
    The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
    Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor
    String cannot be resolved to a type
我已经检查了控制器,在
src/controllers
dir中看起来很好:

package controllers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class HelloController implements Controller {

    public ModelAndView handleRequest(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {

              String Mess = "Hello World!";

              ModelAndView modelAndView = new ModelAndView("hello");
              modelAndView.addObject("message", Mess);

              return modelAndView;
              }

}

您有
http://www.springframework.org/schema/mvc
作为默认值,但您的bean定义属于
http://www.springframework.org/schema/beans
namespace,这应该是问题所在

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


<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix">
        <beans:value>/WEB-INF/jsp/</beans:value>
    </beans:property>


为什么您不使用与其他spring JAR相同版本的spring webmvc?当我从下载spring框架时,它不在内部,所以我用另一个链接下载它:给你:。谢谢,这修复了第3行的一些错误。现在错误看起来不同了。我已经更新了帖子以详细说明结果,但我同意你的看法,错误在
dispatcherservlet.xml
fileOhh中,我发现了一个可能有用的链接:。因此,现在错误被放置在我的控制器上。我认为是时候接受答案了。非常感谢你和其他人。
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
...">


<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix">
        <beans:value>/WEB-INF/jsp/</beans:value>
    </beans:property>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">


    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/jsp/</value>
        </property>

        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>