zoukankan      html  css  js  c++  java
  • DispatcherServlet和ContextLoaderListener是什么?

    20180509 check

    接收到HTTP请求后,DispatcherServlet 询问HandlerMapping (configuration files) 去请求合适的Controller。Controller接受请求后,调用合适的service方法,然后set model data,接下来返回视图(view)给DispatcherServlet。DispatcherServlet从ViewResolver 选择定义好的视图给request请求。一旦视图确定下来,DispatcherServlet 传递model data给最终渲染到浏览器上的视图。

    <web-app>
      <display-name>Archetype Created Web Application</display-name>
       
      <servlet>
            <servlet-name>spring</servlet-name>
                <servlet-class>
                    org.springframework.web.servlet.DispatcherServlet
                </servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
     
        <servlet-mapping>
            <servlet-name>spring</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
         
    </web-app>

    ContextLoaderListener 读取spring配置文件(“contextConfigLocation” in web.xml),解析它、加载定义在配置文件中的beans。

    <servlet>
            <servlet-name>spring</servlet-name>
            <servlet-class>
                org.springframework.web.servlet.DispatcherServlet
            </servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                    WEB-INF/spring-dao-hibernate.xml,
                    WEB-INF/spring-services.xml,
                    WEB-INF/spring-security.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>

     注:也可以将多个context files放到一个已经存在的配置文件中

    <beans>
        <import resource="spring-dao-hibernate.xml"/>
        <import resource="spring-services.xml"/>
        <import resource="spring-security.xml"/>
         
        ... //Other configuration stuff
     
    </beans>

    <context:annotation-config> = Scanning and activating annotations in “already registered beans”.

    <context:component-scan> = Bean Registration + Scanning and activating annotations

  • 相关阅读:
    hdu5358 推公式+在一个区间内的尺取+枚举法
    poj3349 散列表(hash)
    hdu3282 链表或者对顶堆
    hdu5178 尺取
    hdu5672 尺取
    hdu3244完全背包+二分答案 留坑
    hdu5256 二分求LIS+思维
    hdu5646数学构造+二分
    hdu4190 二分答案
    Python中Scapy网络嗅探模块的使用
  • 原文地址:https://www.cnblogs.com/skyball/p/9012146.html
Copyright © 2011-2022 走看看