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中。

posted on 2011-09-20 11:01  jinspire  阅读(3148)  评论(0编辑  收藏  举报

导航