java.io.FileNotFoundException:无法打开ServletContext资源[/WEB-INF/SpringDispatcher-servlet.xml] [英] java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-servlet.xml]

查看:101
本文介绍了java.io.FileNotFoundException:无法打开ServletContext资源[/WEB-INF/SpringDispatcher-servlet.xml]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动应用程序时出现此错误

When I launch my application I get this error

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-servlet.xml]
 nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-servlet.xml]

同时,我没有像SpringDispatcher-servlet.xml这样的文件,我的web.xml或mvc-dispatcher-servlet.xml文件中也没有我的WEB-INF文件夹。

Meanwhile, I dont have any file like SpringDispatcher-servlet.xml neither do I in my web.xml or mvc-dispatcher-servlet.xml file defined in my WEB-INF folder.

web.xml文件

<context-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>SpringDispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    </servlet>
    <servlet-mapping>
        <servlet-name>SpringDispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </context-param>

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

mvc-dispatcher-servlet.xml文件

<context:component-scan base-package="aish.vaishno.musicstore.controller" />

    <mvc:annotation-driven />

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

请问如何找到该文件

/WEB-INF/SpringDispatcher-servlet.xml

请我怎么了?

推荐答案

在您的web.xml中,您已将servlet定义为

In your web.xml you have define the servlet to be

<servlet>
    <servlet-name>SpringDispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

</servlet>

因此,您需要创建一个名为 SpringDispatcher-servlet.xml 的文件在您的 WEB-INF 文件夹中。这就是它的工作原理。如果将servlet名称更改为调度程序,则文件名应为dispatcher-servlet.xml。



您的SpringDispatcher-servlet.xml包含您的Spring上下文的定义。看看这个教程

therefore, you nee to create a file named SpringDispatcher-servlet.xml inside your WEB-INF folder. This is just how it works. If you change the servlet-name to be dispatcher then the file name should be dispatcher-servlet.xml.

Your SpringDispatcher-servlet.xml contains the definitions of your spring context. Take a look on this tutorial.

这篇关于java.io.FileNotFoundException:无法打开ServletContext资源[/WEB-INF/SpringDispatcher-servlet.xml]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆