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

一个人想着一个人 提交于 2019-12-06 15:10:28

Spring is looking SpringDispatcher-servlet.xml in your web project and as it is unable to find it, it is throwing an exception.

You can override the dispatcher servlet xml file like this - providing blank arguments.

 <servlet>
    <servlet-name>SpringDispatcher</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
  </servlet>

When you define Dispatcher servlet in web.xml spring expects Web application context name as Disptacherservletname-servlet.xml under /WEB-INF/ . In your case it should be SpringDispatcher-servlet.xml not mvc-dispatcher-servlet.xml

Or you can use contextConfigLocation parameter to follow your own naming conventions.

<servlet>
    <servlet-name>SpringDispatcher</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </init-param>
  </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>

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!