Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatche...

这是因为我把 [/WEB-INF/dispatcher-servlet.xml]的位置换成了[config/springmvc/dispatcher-servlet.xml]

因此idea在原来的位置找不到这个文件,怎么办呢

Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatche..._第1张图片

 

原来还是在web.xml里面做文章, 添加两行代码即可, 就是在dispatcher的servlet申明的时候, 添加初始化路径

源代码: 

    <servlet>
        <servlet-name>dispatcherservlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
        <load-on-startup>1load-on-startup>
    servlet>
    <servlet-mapping>
        <servlet-name>dispatcherservlet-name>
        <url-pattern>*.formurl-pattern>
    servlet-mapping>

 

修改后的代码: 

    <servlet>
        <servlet-name>dispatcherservlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
        
            contextConfigLocation    
  
classpath:config/springmvc/dispatcher-servlet.xml
    
  <load-on-startup>1load-on-startup> 
servlet>


dispatcher
*.form
 

之后, idea能找到dispatcher-servlet.xml文件, 问题解决!

 

 

 

参考资料: https://www.cnblogs.com/yxdz/p/7528351.html

转载于:https://www.cnblogs.com/zjulanjian/p/10997932.html

你可能感兴趣的:(Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatche...)