Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Model view controller 如何配置Spring DispatcherServlet使用的xml配置文件名?_Model View Controller_Spring_Config - Fatal编程技术网

Model view controller 如何配置Spring DispatcherServlet使用的xml配置文件名?

Model view controller 如何配置Spring DispatcherServlet使用的xml配置文件名?,model-view-controller,spring,config,Model View Controller,Spring,Config,文档说明,默认情况下,DispatcherServlet的(WebApplication?)配置文件是通过在servlet名称后附加“-servlet.xml”找到的,但我需要显式配置该文件的名称。当然,Spring文档没有描述如何不使用默认值 有什么建议吗 试试看: <servlet> <servlet-name>app</servlet-name> <servlet-class>org.springframework.web.servl

文档说明,默认情况下,DispatcherServlet的(WebApplication?)配置文件是通过在servlet名称后附加“-servlet.xml”找到的,但我需要显式配置该文件的名称。当然,Spring文档没有描述如何不使用默认值

有什么建议吗

试试看:

<servlet>
  <servlet-name>app</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/filename.xml</param-value>
  </init-param>
  <load-on-startup>2</load-on-startup>
</servlet>

应用程序
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/filename.xml
2.

这不是应用程序上下文位置吗?我们当前的配置将此设置为空值(我不知道为什么这样做)。最后,我将ContextLoaderListener配置为加载显式WebApplicationContext文件(其名称取决于环境变量),然后使用contextAttribute参数,该参数的值为“org.springframework.web.context.WebApplicationContext.ROOT”,以包括(我假设)ContextLoaderListener加载的所有内容。你能看出它的缺点吗?完整示例:。正如您所看到的,它不是应用程序上下文位置。应用程序上下文位置在顶部定义