做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-webdisplay-name>
<welcome-file-list>
<welcome-file>index.htmlwelcome-file>
<welcome-file>index.htmwelcome-file>
<welcome-file>index.jspwelcome-file>
<welcome-file>default.htmlwelcome-file>
<welcome-file>default.htmwelcome-file>
<welcome-file>default.jspwelcome-file>
welcome-file-list>
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:spring/applicationContext*.xmlparam-value>
context-param>
//异常:Could not open ServletContext resource[/WEB-INF/springmvc-servlet.xml].没有配置Spring配置文件
//因为springmvc.xml也可以不在init-param标签中配置.也就是在context-param配置.
//所以就将springmvc的配置文件和spring的配置文件一起配置.配置的为Springmvc文件路径,但是两个路径是不同的,所以异常
<listener>
//在intellij中需要添加lib的依赖jar.不然异常:标签不允许出现异常
<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>
<servlet>
<servlet-name>springmvc-webservlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
<init-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:spring/springmvc.xmlparam-value>
init-param>
servlet>
<servlet-mapping>
<servlet-name>springmvc-webservlet-name>
<url-pattern>*.actionurl-pattern>
servlet-mapping>
web-app>