springmvc/mybaits的web.xml配置:Could not open ServletContext resource [/WEB-INF/springmvc-servlet.xml]

1 篇文章 0 订阅
0 篇文章 0 订阅

做Springmvc和mybatis整合的时候启动tomcat报异常Could not open ServletContext resource [/WEB-INF/springmvc-servlet.xml]

原因:spring的配置文件没有加载,和mybatis的核心配置文件搞混了,而且在intellij中需要添加lib的依赖

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/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

    id="WebApp_ID"version="2.5">

    <display-name>springmvc-web</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:spring/applicationContext*.xml</param-value>

    </context-param>

//异常:Could not open ServletContext resource[/WEB-INF/springmvc-servlet.xml].没有配置Spring配置文件

//因为springmvc.xml也可以不在init-param标签中配置.也就是在context-param配置.

//所以就将springmvc的配置文件和spring的配置文件一起配置.配置的为Springmvc文件路径,但是两个路径是不同的,所以异常

    <!-- 使用监听器加载Spring配置文件 -->

    <listener>

//在intellij中需要添加lib的依赖jar.不然异常:标签不允许出现异常

       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    <!-- 配置SrpingMVC的前端控制器 -->

    <servlet>

       <servlet-name>springmvc-web</servlet-name>

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

       <init-param>

           <param-name>contextConfigLocation</param-name>

           <param-value>classpath:spring/springmvc.xml</param-value>

       </init-param>

    </servlet>

    <servlet-mapping>

       <servlet-name>springmvc-web</servlet-name>

       <!-- 配置所有以action结尾的请求进入SpringMVC -->

       <url-pattern>*.action</url-pattern>

    </servlet-mapping>

</web-app>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值