• Struts2初始化过程代码分析


    根据web.xml的配置

    image

    调用FilterDispatcher.init(FilterConfig filterConfig)

    1. 创建org.apache.struts2.Dispatcher,并调用init()方法

    1.1. 创建com.opensymphony.xwork2.config.ConfigurationManager,其中属性List<ContainerProvider> containerProviders存放所有配置。

    1.2. init_DefaultProperties();

    初始化DefaultPropertiesProvider,其中方法register(ContainerBuilder builder, LocatableProperties props)实现会从org/apache/struts2/default.properties加载settings到props中,最后将其加入containerProviders.

    1.3. init_TraditionalXmlConfigurations();

    默认根据struts-default.xml,struts-plugin.xml,struts.xml (可根据init-param:config 修改加载路径) 分别创建三个 org.apache.struts2.config. StrutsXmlConfigurationProvider,其中方法register实现默认会从相应配置文件读取props加载到setting中,会将bean放入ContainerBuilder中,最后将三个containerProviders并加入containerProviders

    1.4. init_LegacyStrutsProperties();

    初始化LegacyPropertiesConfigurationProvider,并加入containerProviders

    1.5. init_CustomConfigurationProviders();

    根据init-param:configProviders初始化实现了ContentProvider接口的类,并加入containerProviders.

    1.6. init_FilterInitParameters() ;

    初始化一个ConfigurationProvider,将定义的initParams从web.xml中读入,放入props

    1.7. init_AliasStandardObjects() ;

    初始化BeanSelectionProvider

    1.8. Container container = init_PreloadConfiguration()

    1.8.1. 在初始化时会去执行configuration.reloadContainer(getContainerProviders());

    类:com.opensymphony.xwork2.config.impl.DefaultConfiguration

    方法:reloadContainer(List<ContainerProvider> providers)

    初始化ContainerProperties props,ContainerBuilder builder

    遍历containerProviders,调用其register(builder, props)方法

    再将props注入builder中。

  • 相关阅读:
    1436 孪生素数 2
    1702 素数判定 2
    第五章 Spring3.0 、Hibernate3.3与Struts2的整合 基于Annotation
    逻辑服务器和数据缓存服务器交互方式整理
    Solr学习(2) Solr4.2.0+IK Analyzer 2012
    hdu4288 Coder
    解决Robotium测试用例crash问题
    FineUI_动态绑定Grid
    Protection 5 ---- Priviliege Level Checking 2
    用户权限管理
  • 原文地址:https://www.cnblogs.com/jinspire/p/2182240.html
Copyright © 2020-2023  润新知