struts2中配置文件加载的顺序是什么?

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

 

需要注意的是,后加载文件中的配置会将先加载文件中的配置覆盖。

posted @ 2016-04-16 21:25  hoey94  阅读(2143)  评论(0编辑  收藏  举报