码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-04-16 22:52:08      阅读:330      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

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

标签:

原文地址:http://www.cnblogs.com/zyh1994/p/5399421.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!