The dispatcher is initialized in the Struts2 Strutsprepareandexecutefilter interceptor.
In the Init method of the Dispatcher class, the load order of the configuration files is defined (the source code below)
public void init () {
if (ConfigurationManager = = null) {
ConfigurationManager = Createconfigurationmanager (defaultbeanselectionprovider.default_bean_name);
}
try {
Init_filemanager ();
Init_defaultproperties (); [1]
Init_traditionalxmlconfigurations (); [2]
Init_legacystrutsproperties (); [3]
Init_customconfigurationproviders (); [5]
Init_filterinitparameters (); [6]
Init_aliasstandardobjects (); [7]
Container Container = Init_preloadconfiguration ();
Container.inject (this);
Init_checkweblogicworkaround (container);
if (!dispatcherlisteners.isempty ()) {
for (Dispatcherlistener l:dispatcherlisteners) {
L.dispatcherinitialized (this);
}
}
} catch (Exception ex) {
if (log.iserrorenabled ())
Log.error ("Dispatcher initialization Failed", ex);
throw new Strutsexception (ex);
}
}
The order in which they are loaded is:
1.default.properties file
Function: Defines all constants in the STRUTS2 framework
Location: org/apache/struts2/default.properties
2.struts-default.xml
Function: Configuration of Bean,interceptor,result and so on.
Location: Core core jar package in struts.
Struts-plugin.xml
It is the configuration file for the plug-in used in the STRUTS2 framework.
Struts.xml
We make the configuration file used by Struts2.
3. Custom Struts.properties
is to customize the constants.
4.web.xml
It is important to note that the configuration in the post-load file will overwrite the configuration in the loaded file first.
What is the order in which the configuration files are loaded in struts2?