我迟到了,我们可以在web应用程序的类路径中的任何目录中配置struts.xml,但如果web.xml文件位于"/com/resources/“目录中,则使用web.xml中过滤器配置的"config”init参数提供位置,如下所示。
代码语言:javascript运行复制
如果我们不提供一个配置init参数,默认情况下struts2采用3个值"struts-default.xml,struts-plugin.xml,struts.xml",您可以看到下面的struts2 Dispatcher类代码,它将这3个文件配置到配置管理器。
代码语言:javascript运行复制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));
}