struts2的StrutsPrepareAndExecuteFilter攔截器中對Dispatcher進行了初始化
在Dispatcher類的init方法中定義了配置文件的加載順序(下面是源碼)
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);
}
}
他們加載的順序分別是:
1.default.properties文件
作用:定義了struts2框架中所有常量
位置: org/apache/struts2/default.properties
2.struts-default.xml
作用:配置了bean,interceptor,result等。
位置:在struts的core核心jar包.
struts-plugin.xml
它是struts2框架中所使用的插件的配置文件。
struts.xml
我們使struts2所使用的配置文件。
3.自定義的struts.properties
就是可以自定義常量。
4.web.xml
需要注意的是,后加載文件中的配置會將先加載文件中的配置覆蓋。