Struts2中struts.xml文件的加载过程
来源:互联网 发布:行程路线图制作软件 编辑:程序博客网 时间:2024/05/20 08:43
1.启动tomcat过程中,加载web.xml文件。
2.找到web.xml中的org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter类。
3.在StrutsPrepareAndExecuteFilter中调用了init方法,创建一个了InitOperations()对象,并且调用了initDispatcher(config);方法。在class文件中的源码如下:
public void init(FilterConfig filterConfig) throws ServletException { InitOperations init = new InitOperations(); try { FilterHostConfig config = new FilterHostConfig(filterConfig); init.initLogging(config); Dispatcher dispatcher = init.initDispatcher(config);4.在InitOperations类中调用了initDispatcher(config)方法,在该方法中又调用了Dispatcher的init方法,class文件中的源码如下:
public Dispatcher initDispatcher( HostConfig filterConfig ) { Dispatcher dispatcher = createDispatcher(filterConfig); dispatcher.init(); return dispatcher;
5.接下来我们跳到Dispatcher类中调用init()方法处,源码如下:
public void init() { if (configurationManager == null) { configurationManager = createConfigurationManager(BeanSelectionProvider.DEFAULT_BEAN_NAME); } try { init_DefaultProperties(); // [1] init_TraditionalXmlConfigurations(); // [2] init_LegacyStrutsProperties(); // [3] init_CustomConfigurationProviders(); // [5] init_FilterInitParameters() ; // [6] init_AliasStandardObjects() ; // [7]
上面的源码调用了init_TraditionalXmlConfigurations()方法,接着进到该方法中:
private void init_TraditionalXmlConfigurations() { String configPaths = initParams.get("config"); if (configPaths == null) { configPaths = DEFAULT_CONFIGURATION_PATHS; }在该方法中可以看到定义了一个配置文件路径,DEFAULT_CONFIGURATION_PATHS,然后继续跟踪源码。
在该类中源码如下:
private static final String DEFAULT_CONFIGURATION_PATHS = "struts-default.xml,struts-plugin.xml,struts.xml";
说明此时加载了struts-default.xml,struts-plugin.xml,struts.xml三个文件。
注意:
1.struts.xml文件必须放在classpath的根目录下。
2.名字必须为struts.xml
3.因为整个加载过程写在了过滤器的init方法中,所以tomcat启动的时候就把该文件加载了。
1 0
- Struts2中struts.xml文件的加载过程
- struts2中struts.xml什么时候加载…
- Struts2中struts.xml文件详解
- struts2设置加载非默认路径的struts.xml文件解决方案+Struts2初学 Struts2的action接收用户数据方式
- Struts2设置加载非默认路径的struts.xml文件的方法
- Struts2 Chapter2 struts.xml文件的配置
- struts2 中struts.xml
- Struts2中如何加载多个struts.xml配置文件
- struts2中web.xml配置struts.xml文件
- [Struts2]struts.xml中result的path
- struts2.2中struts.xml的注意事项
- Struts2 中struts.xml的骨架
- Struts2中有关struts-default.xml,struts.xml,struts.properties文件详解
- [转载]Struts2中有关struts-default.xml,struts.xml,struts.properties文件详解
- Struts2中有关struts-default.xml,struts.xml,struts.properties文件详解
- Struts2中有关struts-default.xml,struts.xml,struts.properties文件详解
- Struts2中有关struts-default.xml,struts.xml,struts.properties文件详解
- Struts2中有关struts-default.xml,struts.xml,struts.properties文件详解
- java
- 百度面试题 最长公共子串-动态规划法
- 数据库设计(2)生命周期
- 黑马程序员_IO流
- 济宁惠普第一个文章
- Struts2中struts.xml文件的加载过程
- Median of Two Sorted Arrays
- mongodb 按照时间聚类 java
- 仿qq聊天界面
- asp.net如何解决传递中文参数乱码问题
- xml文件解析并显示到Android手机 spinner的应用
- 快速创建九宫格
- HDU 1702 ACboy needs your help again!(模拟 队列 栈)
- Hive函数row_number实现