Я опоздал на вечеринку, мы можем настроить struts.xml в любом каталоге в classpath веб-приложения, но указать местоположение, используя параметр config "config" конфигурации фильтра в web.xml, как показано ниже, если мой файл struts.xml находится в каталоге "/ com / resources /".
<filter>
<filter-name>action</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,/com/resources/struts.xml</param-value>
</init-param>
</filter>
Если мы не предоставим конфигурационный параметр init Struts2 по умолчанию принимает 3 значения "struts-default.xml, struts-plugin.xml, struts.xml", вы можете увидеть ниже код класса struts2 Dispatcher, который настроит эти 3 файла в диспетчер конфигурации.
String configPaths = (String)this.initParams.get("config");
if (configPaths == null) {
configPaths = "struts-default.xml,struts-plugin.xml,struts.xml";
}
String[] files = configPaths.split("\\s*[,]\\s*");
for (String file : files)
if (file.endsWith(".xml")) {
if ("xwork.xml".equals(file))
this.configurationManager.addContainerProvider(createXmlConfigurationProvider(file, false));
else
this.configurationManager.addContainerProvider(createStrutsXmlConfigurationProvider(file, false, this.servletContext));
}