zoukankan      html  css  js  c++  java
  • SSM框架出现:class path resource [SpringMvc.xml] cannot be opened because it does not exist

    错误: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>
  • 相关阅读:
    【webpack系列】从零搭建 webpack4+react 脚手架(一)
    js常见的面试题
    java中读取资源文件的方法
    java servlet的域对象
    java 静态资源访问详解
    java servlet简述
    mysql免解压版的配置
    java网络编程
    java单例设计模式
    java多线程及线程安全详解
  • 原文地址:https://www.cnblogs.com/zll20153246/p/9744400.html
Copyright © 2011-2022 走看看