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

  • 相关阅读:
    【妖精眼镜】
    神兽保佑-代码无BUG
    Eclipse常用快捷键 及 不格式化注释
    Android dialog 全屏
    eclipse 改变颜色,背景
    GOOGLE和百度的长域名
    Android在ArrayAdapter<>里如何得到List<>的Items
    Android 仿微信朋友圈发动态功能(相册图片多选)
    Android 让GridView的高度为Wrap_content根据内容自适应高度
    C++中函数的返回值
  • 原文地址:https://www.cnblogs.com/skyball/p/9012146.html
Copyright © 2011-2022 走看看