初学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应用的配置文件 (配置常量 )
后加载配置文件中修改的常量的值会覆盖前面配置文件修改的常量的值