Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.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
Java SpringMVC中的不同上下文是如何工作的?_Java_Spring_Configuration_Web.xml - Fatal编程技术网

Java SpringMVC中的不同上下文是如何工作的?

Java SpringMVC中的不同上下文是如何工作的?,java,spring,configuration,web.xml,Java,Spring,Configuration,Web.xml,我的Spring MVC Webapp有以下配置。我想从概念上了解servlet-context.xml中的contextConfigLocation(它是appServlet的conf)与其他文件安全性、tiles。。。我不明白它是如何工作的,因为如果我将我的tiles-context.xml配置放在servlet上下文中,应用程序就会工作,而在另一种情况下不会,但安全性工作正常。这个文件中的bean不也在appServlet容器中吗?是否存在不止一个上下文 <!-- Dispatche

我的Spring MVC Webapp有以下配置。我想从概念上了解servlet-context.xml中的contextConfigLocation(它是appServlet的conf)与其他文件安全性、tiles。。。我不明白它是如何工作的,因为如果我将我的tiles-context.xml配置放在servlet上下文中,应用程序就会工作,而在另一种情况下不会,但安全性工作正常。这个文件中的bean不也在appServlet容器中吗?是否存在不止一个上下文

<!-- DispatcherServlet Conf - Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>


<!-- Spring configuration files in XML -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:security-context.xml
        classpath:tiles-context.xml
        ...
    </param-value>
</context-param>

appServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
类路径:servlet-context.xml
1.
appServlet
/
上下文配置位置
类路径:security-context.xml
类路径:tiles-context.xml
...
看一看

了解根上下文和servlet上下文的区别

您可以使用如下配置定义多个servlet上下文

<servlet>
<servlet-name>api-dispatcher</servlet-name>
<servlet-class>
    org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/api-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>api-dispatcher</servlet-name>
<url-pattern>/rest/*</url-pattern>

api调度程序
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/api-dispatcher-servlet.xml
1.
api调度程序
/休息/*

当url模式为/rest/*时,可以访问上述上下文。这是在spring上配置多个独立上下文的方式。

您可以查看此链接。类似问题