初學Struts2框架,今天沒事就寫篇文章,當做學習筆記來用吧!衆所周知,都知道Struts2是web層應用框架,那就從啓動web應用加載Struts2開始來說。
Struts2配置文件加載順序
還是看看源碼,Struts2的核心就是過濾器,即StrutsPrepareAndExecuteFilter核心過濾器,通過查看StrutsPrepareAndExecuteFilter
由上對應產生文件依次如下:
init_DefaultProperties(); // [1]---- org/apache/struts2/default.properties
init_TraditionalXmlConfigurations(); // [2] --- struts-default.xml,struts-plugin.xml,struts.xml
init_LegacyStrutsProperties(); // [3] --- 自定義struts.properties
init_CustomConfigurationProviders(); // [5] ----- 自定義配置提供
init_FilterInitParameters() ; // [6] ----- web.xml
init_AliasStandardObjects() ; // [7] ---- Bean加載
總結:【前三個是默認的,不用關注,後面三個需要注意】
① default.properties 該文件保存在 struts2-core-2.3.7.jar 中 org.apache.struts2包裏面 (常量的默認值)
② struts-default.xml 該文件保存在 struts2-core-2.3.7.jar (Bean、攔截器、結果類型 )
③ struts-plugin.xml 該文件保存在struts-Xxx-2.3.7.jar (在插件包中存在 ,配置插件信息 )struts-config-browser-plugin-2.3.7.jar裏面有
④ struts.xml 該文件是web應用默認的struts配置文件 (實際開發中,通常寫struts.xml )
⑤ struts.properties 該文件是Struts的默認配置文件 (配置常量 )
⑥ web.xml 該文件是Web應用的配置文件 (配置常量 )
後加載配置文件中修改的常量的值會覆蓋前面配置文件修改的常量的值