Java spring4中的上下文初始化失败

Java spring4中的上下文初始化失败,java,spring-mvc,servlets,Java,Spring Mvc,Servlets,在maven中运行项目时,我遇到以下错误 org.springframework.beans.factory.BeanDefinitionStoreException: 从ServletContext资源解析XML文档时发生IOException [/WEB-INF/dispatcherservlet.xml];嵌套异常是 java.io.FileNotFoundException:无法打开ServletContext资源 [/WEB-INF/dispatcher servlet.xml] 我尝

在maven中运行项目时,我遇到以下错误

org.springframework.beans.factory.BeanDefinitionStoreException: 从ServletContext资源解析XML文档时发生IOException [/WEB-INF/dispatcherservlet.xml];嵌套异常是 java.io.FileNotFoundException:无法打开ServletContext资源 [/WEB-INF/dispatcher servlet.xml]

我尝试过在internet上指定的解决方案,比如servlet名称应该与我们将在其中指定context param的文件相同,但它仍然不起作用

Web.xml


Web应用程序创建的原型
调度员
org.springframework.web.servlet.DispatcherServlet
1.
调度员
/
dispatcher.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.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:p`enter code here`roperty name="suffix" value=".jsp" />
    </beans:bean>
    <context:component-scan base-package="com.test.controller" />
</beans:beans>

将dispatcher-servlet.xml文件直接放在WEB.xml所在的WEB-INF目录中。(如果您需要,我可以提供详细答案)


Web应用程序创建的原型
org.springframework.web.context.ContextLoaderListener
-->
调度员
org.springframework.web.servlet.DispatcherServlet
1.
调度员
/

看起来文件名应该是
dispatcher servlet.xml
而不是
dispatcher.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.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:p`enter code here`roperty name="suffix" value=".jsp" />
    </beans:bean>
    <context:component-scan base-package="com.test.controller" />
</beans:beans>
    <web-app>
  <display-name>Archetype Created Web Application</display-name>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>