Struts2的配置文件加载顺序
struts2配置文件说明
框架内置配置文件
default.properties:用于存储可以Struts2配置的环境参数(静态常量参数)
struts-default.xml:用于存储框架默认配置的信息(内置的组件功能都配置在这里)
- struts-plugin.xml:用于配置插件的配置信息(讲注解插件时,再分析)
–自定义配置文件– - struts.properties:配置自定义的环境参数,如果在这里写环境参数,会覆盖默认default.properties内置的环境参数
- struts.xml:默认自定义配置文件,配置自定义信息类与请求的关系。(用户用到的)
配置文件的加载顺序
了解加载顺序的原因是:让我们知道,后面加载的配置会覆盖前面的 配置。
我们通过核心控制器(StrutsPrepareAndExecuteFilter)来分析
通过这段代码分析配置文件的加载顺序
init_DefaultProperties(); // [1] –default.properties
init_TraditionalXmlConfigurations(); // [2]struts-default.xml,struts-plugin.xml
init_LegacyStrutsProperties(); // [3] –struts.properties
init_CustomConfigurationProviders(); // [5]–struts.xml
init_FilterInitParameters() ; // [6] –web.xml参数
为什么要指定配置文件的执行顺序
答:为了知道我们配置的信息覆盖了原来的哪些配置文件!!!!!
struts.properties 覆盖 default.properties配置的参数struts.xml 覆盖 struts-default.xml,struts-plugin.xml。
如果struts.xml不是覆盖内置的配置,而是在默认的配置上追加自身的配置。使用extends