做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>