如题,Struts加载时会自动加载struts.xml,并通过include加载其他xml配置文件,struts时如何实现自动加载(filerDispatcher吗?),要怎么实现动态加载这些配置,就是需要的时候加载(自定义加载),这个配置文件加载类要怎么写?

解决方案 »

  1.   

    org.apache.struts2.dispatcher.Dispatcher
    private static final String DEFAULT_CONFIGURATION_PATHS = "struts-default.xml,struts-plugin.xml,struts.xml";
    //...
        private void init_TraditionalXmlConfigurations() {
            String configPaths = initParams.get("config");
            if (configPaths == null) {
                configPaths = DEFAULT_CONFIGURATION_PATHS;
            }
            String[] files = configPaths.split("\\s*[,]\\s*");
            for (String file : files) {
                if (file.endsWith(".xml")) {
                    if ("xwork.xml".equals(file)) {
                        configurationManager.addConfigurationProvider(new XmlConfigurationProvider(file, false));
                    } else {
                        configurationManager.addConfigurationProvider(new StrutsXmlConfigurationProvider(file, false, servletContext));
                    }
                } else {
                    throw new IllegalArgumentException("Invalid configuration file name");
                }
            }
        }
      

  2.   

    在struts.xml里</struts>前加入
    <include file="struts-res.xml" />
    <include file="struts-sso.xml" />
      

  3.   

    要自己写一个类来继承fiterDispatch吗,要实现那些方法.
    还有我想当我需要使用某个模块时,加载它的xml配置文件,可以直接用configurationManager.addConfigurationProvider(new XmlConfigurationProvider(file,false))吗,还是写个继承类.
    我很菜,希望说得详细点.
    还有,struts是先加载xml,然后再需要时加载action.class文件吗?
      

  4.   


    在struts.xml里 </struts>前加入 
    <include file="struts-res.xml" /> 
    <include file="struts-sso.xml" />