• 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

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

  • 相关阅读:
    JVM 垃圾回收器工作原理及使用实例介绍(转载自IBM),直接复制粘贴,需要原文戳链接
    装tomcat和nginx心得
    jms的俩种模式
    裸奔Spring(1)
    一个最小mybatis
    SpringBoot和数据库连接
    SpringBoot的基础Pom
    SpringBoot读取配置文件
    埃拉托斯特尼素数筛法
    hdu 1175 连连看
  • 原文地址:https://www.cnblogs.com/zyh1994/p/5399421.html
Copyright © 2020-2023  润新知