zoukankan      html  css  js  c++  java
  • tomcat与springmvc 结合 之---第17篇 StandContext容器和SpringMVC的WebApplicationContext的联系

    writedby 张艳涛,

    上一篇分析了,dispatcherservlet通过getServletConfig 方法获取了web.xml定义的<param-init>属性的过程

    那么在如果在Controller里面使用servletContext 和seervletConfig对象怎么办?

    public class NoannaContoller implements Controller , EnvironmentAware, ApplicationContextAware {
        @Override
        public ModelAndView handleRequest(HttpServletRequest request,
                                          HttpServletResponse response) throws {}
        private Environment environment=null;
    
        @Override
        public void setEnvironment(Environment environment) {
            this.environment=environment;
        }
        private    ApplicationContext applicationContext=null;
        @Override
        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            this.applicationContext=applicationContext;
        }
    }

    答案是实现XXXAware,那么如果给红色的打个断点,那么看看,

    可以看到是在bean对象noannaController对象初始化的时候给对象进行了赋值,

    调用关系

    这里就非常明确了实现aware接口的类,会在创建applicationcontext过程中将自己传给aware类

    这里还设计一个问题就是这个类叫org.springframework.web.context.support.XmlWebApplicationContext,那创建之后会存到tomcat的StandardContext容器的

    ApplicationContext中,存的key 是org.springframework.web.servlet.FrameworkServlet.CONTEXT.springmvc

    如图

    注:org.springframework.web.servlet.FrameworkServlet.CONTEXT.springmvc 是由

    SERVLET_CONTEXT_PREFIX + getServletName();
    其中org.springframework.web.servlet.FrameworkServlet.CONTEXT. + servlet的名字来确定
        <servlet>
            <servlet-name>springmvc</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <!-- contextConfigLocation配置springmvc加载的配置文件(配置处理器、映射器等) 如果不配置contextConfigLocation,默认加载的是/WEB-INF/servlet名称-servlet.xml(springmvc-servlet.xml) -->
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:springmvc.xml</param-value>
            </init-param>
        </servlet>

     

  • 相关阅读:
    TFS 2010 备份和恢复的完整解决方案
    PDC10 微软宣布TFS成功移植到云计算平台Windwos Azure
    基于Visual Studio 2010 进行敏捷/Scrum模式开发
    配置TFS服务器所需要的数据库权限
    TechEd2011 Session Visual Studio ALM项目管理 端到端的跟踪与控制
    微软云计算培训 (ethos)
    2007 Office System Driver: Data Connectivity Components
    Ajax post时需要注意的问题
    JQuyer $.post 与 $.ajax 访问WCF ajax service 时的问题
    ColorPicker js control
  • 原文地址:https://www.cnblogs.com/zytcomeon/p/15035549.html
Copyright © 2011-2022 走看看