1.web.xml配置文件

首先是web.xml文件的主要配置

下面是web.xml配置文件的一个示例

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!--web工程项目名称-->
    <display-name>Cloud</display-name>

    <!--定义param-->
    <!--production-->
    <!--development-->
    <context-param>
        <param-name>spring.profiles.default</param-name>
        <param-value>production</param-value>
    </context-param>

    <!-- Spring配置文件开始 用一个上下文参数指定了根容器的配置文件路径-->
    <!-- Spring The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:spring-*.xml</param-value>
    </context-param>

    <!--定义了一个监听器,用来初始化根容器 -->
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <!--自定义Listener-->
    <listener>
        <listener-class>
            com.cloud.oss.infra.listener.CloudServletStartListener
        </listener-class>
    </listener>

    <!--对所有请求进行过滤-->
    <!-- 字符集编码配置开始 -->
    <filter>
        <filter-name>Encoding</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <!--对于给定的请求进行过滤,比如权限、跨域设置等-->
    <!--自定义Filter -->
    <filter>
        <filter-name>security</filter-name>
        <filter-class>com.cloud.oss.infra.filter.RequestFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>security</filter-name>
        <url-pattern>/api/*</url-pattern>
    </filter-mapping>

    <!-- Spring MVC配置开始 定义了一个servlet,用来接管所有的请求,也通过参数形式指定了配置文件路径。-->
    <!-- Processes application requests -->
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath*:spring-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!--Hibernate的session配置-->
    <!-- 配置Session -->
    <filter>
        <filter-name>openSession</filter-name>
        <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>openSession</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

 

posted @ 2017-06-07 17:40  桃源仙居  阅读(108)  评论(0)    收藏  举报