1. 程式人生 > >SSM框架出現:class path resource [SpringMvc.xml] cannot be opened because it does not exist

SSM框架出現:class path resource [SpringMvc.xml] cannot be opened because it does not exist

def 文件 ati XML tco character java style cte

錯誤:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist

  錯誤原因:找不到我的springmvc.xml,在下面web.xml中是我引用路徑,網上找到問題classpath指向路徑不是resource路徑,所以一直找不到我的xml文件,

  classpath:到你的class路徑中查找文件,

  classpath*:不僅包含class的路徑,還包括jar文件中(class路徑)進行查找

  解決辦法:在classpath後面在上“*” 可解決問題,“classpath*:springmvc.xml”

技術分享圖片

web.xml代碼:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SSM</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default
.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <!-- 加載spring容器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:ApplicationContext-*.xml</param-value> </context-param> <listener> <listener-class
>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- springmvc前端控制器 --> <servlet> <servlet-name>springMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:SpringMvc.xml</param-value> </init-param> <!-- 在tomcat啟動的時候就加載這個servlet --> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMvc</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> <!-- 配置Post請求亂碼 --> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>

SSM框架出現:class path resource [SpringMvc.xml] cannot be opened because it does not exist