• Springmvc配置文件application.xml 和 spring-servlet.xml


    文章来源:http://blog.csdn.net/tengdazhang770960436/article/details/48395885

    1.SpringMVC 的配置分为两部分 application.xml 和 spring-servlet.xml

    2.两个配置文件的作用和配置位置

    2.1.application.xml :对应的是系统级别的配置,作用范围是系统上下文。

    2.2.spring-servlet.xml:对应的是 controller 级别的配置,作用范围是控制层上下文。

    3.它们在web.xml 中的配置

    3.1.因为 application.xml 是系统级别的上下文,所以它的初始化需要放到 web.xml 中的<context-param>标签中,同时其他的类似定时任务的配置文件等等都是放在这个标签下进行初始化的。

    3.2.因为spring-servlet.xml只是 controller 级别的上下文,说白了就是 servlet 级别的初始化,它不涉及到除了转发之外的任何实体,所以它的作用范围仅仅限制在 servlet 级别,所以它的初始化应该是跟spring 的 DispatcherServlet 初始化在一起,所以就是在 <servlet> 表情中初始化的。它有一个默认值就是【/WEB-INF/remoting-servlet.xml 】,注意配置文件的对应的名称是【 servlet-name】-servlet.xml,所以如果你没有给servlet 制定配置文件的位置,并且在默认位置下也没有配置文件,那么系统启动的时候就会报错。

    注意:对于 servlet配置文件里面应该初始化的东西,除了视图的解析方式、静态资源文件的存放位置、controller的初始化方式之外,其他的都不应该放在 servlet 配置文件中,应为它只负责 请求的转发,返回结果的解析以及静态资源文件的解析,其他的对象的初始化,定时任务...都不应该放到这个配置文件下进行管理。

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 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_3_0.xsd"
        version="3.0" metadata-complete="true">
        
        <!--  这个地方默认加载的是系统的变量的配置文件,它们属于是系统级别的配置  -->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
            classpath:spring/application.xml.xml,
            classpath:spring/spring-quartz.xml
            </param-value>
        </context-param>
        <context-param>
            <param-name>webAppRootKey</param-name>
            <param-value>webapp.root</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
        </listener>
    <!--     <context-param>
            <param-name>logbackConfigLocation</param-name>
            <param-value>classpath:conf/logback.xml</param-value>
        </context-param> -->
    <!--     <listener>
            <listener-class>xorg.springframework.web.util.LogbackConfigListener</listener-class>
        </listener> -->
        <listener>
            <listener-class>com.cloudFarmHDAPI.admin.listener.SystemListener</listener-class>
        </listener>
        
        <!--  这个地方加载的是 servlet 的变量的配置文件,它们属于 controller 级别的配置
            1.如果不配置这个 servlet-context.xml 的配置文件位置,
            那么默认就会去/WEB-INF/servlet-context.xml 下面去寻找这个文件 
            2.如果配置了这个位置,那么它就会去制定位置加载文件
          -->
        <servlet>
            <servlet-name>appServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:spring/servlet-context.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>appServlet</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
        <!-- charactor encoding -->
        <filter>
            <filter-name>encodingFilter</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>encodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
        <!-- shiro security filter -->
        <filter>
            <filter-name>shiroSecurityFilter</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
            <init-param>
                <param-name>targetFilterLifecycle</param-name>
                <param-value>true</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>shiroSecurityFilter</filter-name>
            <url-pattern>/*</url-pattern>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>FORWARD</dispatcher>
            <dispatcher>ERROR</dispatcher>
        </filter-mapping>
        <session-config>  
          <session-timeout>60</session-timeout>  
        </session-config> 
        <welcome-file-list>  
               <welcome-file>index.htm</welcome-file>  
        </welcome-file-list>
    </web-app>
  • 相关阅读:
    js获取当前时间,日期格式为年月日
    create-react-app里添加less
    react css 模块化
    react 点击父级元素 不触发子级元素click事件
    react-router-dom 实现路由左右滑动进入页面的效果
    vue路由左右侧滑动 react路由左右侧滑动
    react 父组件不能直接在子组件上加className,也得用props传递过去
    react 父组件调用子组件方法
    css滚动相关问题记录
    javascript异步编程的几种方法
  • 原文地址:https://www.cnblogs.com/masterhxh/p/13921964.html
Copyright © 2020-2023  润新知