mybatis plus第二讲 web.xml文件

web.xml文件是项目的总的配置文件,本来所有的配置都应该写在这里,但是因为都写在这里会导致web.xml文件太大,层次感不强,所以分成:spring-mybatis.xml、spring-mvc.xml、log4j.properties三个文件,最后将这三个文件都在web.xml文件中“登记”。

spring-mybatis.xml是将spring和mybaits整合在一起,即spring接管了mybatis数据库的连接之类的。

因为spring-mvc太强大,spring有点管不住它了,所以把spring-mvc的配置作为一个单独的文件来弄,

log4j.properties是ssm在运行时,一些出错信息要处理,所以是属于“内部定制”的,因此也必须要有。

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_3_0.xsd" id="WebApp_ID" version="3.0">
        <!-- 工程名 -->
        <display-name>mybatisplus</display-name>
        <!-- 首文件名 -->
        <welcome-file-list>
                <welcome-file>/index.jsp</welcome-file>
        </welcome-file-list>

        <!-- session过期时间 -->

        <session-config>

<session-timeout>60</session-timeout>
</session-config>
        <!-- 过滤防乱码,全部过滤的网址一定是“/*”,而不是“/” 以前用“/”居然网页间的传递一点都不防乱码 -->
<filter>
<filter-name>encode</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>encode</filter-name>
<url-pattern>/*</url-pattern>

</filter-mapping>  


        <!-- 全局变量,即log4j的位置 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
                 <!-- spring-mybatis.xm的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
                     classpath:spring-mybatis.xml
</param-value>
</context-param>
  
<!-- Spring监听器 -->
<listener>
<listener-class>
            org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
  
<!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
  
<!--RequestContextListener将Spring容器与Web容器结合的更加密切。这是可选配置-->
<listener>
<listener-class>
            org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
                <!-- servlet将被spring-mvc.xml接管 -->
<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:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
  
</web-app>

猜你喜欢

转载自blog.csdn.net/jintingbo/article/details/80542059