如何DispatcherServlet的工作,如果我们有多个XML配置文件? [英] How does DispatcherServlet work if we have multiple XML Configuration file?

查看:191
本文介绍了如何DispatcherServlet的工作,如果我们有多个XML配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

如何DispatcherServlet的工作,如果我们有多个XML配置文件,那么,如何Spring应用上下文加载它们及对其操作?

情景:

在我的情况下,我们有一个应该是全球性的应用程序,应用程序应该有 AP {亚太} EM {EUROP-Middleeast},CA {加拿大}和LA {拉丁美洲} 版本。

In my case, we have an application that is supposed to global that is application should have AP{Asia-Pacific}, EM{Europ-Middleeast}, CA{Canada} and LA{Latin America} Versions.

目前,我们有这是一个地区申请 EM 和它有它的 XML配置文件即EM-servelt.xml 再有就是普通的的web.xml 现在文件为亚太地区我们有另一个 AP-servlet.xml中文件,并通过这两个 EM-servlet.xml中 AP-servlet.xml中的方式文件将有相同的bean的名字,但他们会指着不​​同的封装控制器,因此,例如,EM将指向类似 com.em.DomainController 和AP将指向 com.ap.DomainController

Currently, we have Application for one region that is EMand its has its XML Configuration File i.e, em-servelt.xml and then there is generic web.xml file now for AP region we have another ap-servlet.xml file and by the way both em-servlet.xml and ap-servlet.xml file would have same bean names but they would be pointing to Controllers in different packages, so for example, em would be pointing to something like com.em.DomainController and ap would be pointing to com.ap.DomainController.

所以我的问题是

请求如何映射到不同的控制器以及如何请求被确认,这样它应该从AP-servlet.xml中或EM-servlet.xml中读?

How is the request mapped to different controllers and how request is being recognized so that it should read from ap-servlet.xml or em-servlet.xml ?

我希望我能够清楚地说明我的问题。

I hope am able to clearly state my question.

推荐答案

的web.xml 文件可以配置多个 DispatcherServlet的实例中,每一个具有其自己的配置。每个 DispatcherServlet的实例配置一个的WebApplicationContext 从其他分离 DispatcherServlet的实例,这样你就可以使用同一个bean的名字,不影响其他应用程序上下文。

The web.xml file can configure multiple DispatcherServlet instances, each having its own configuration. Each DispatcherServlet instance configures a WebApplicationContext separate from other DispatcherServlet instances, so you can use the same bean names without affecting the other application context.

<!-- configured by WEB-INF/ap-servlet.xml -->
<servlet>
    <servlet-name>ap</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- configured by WEB-INF/em-servlet.xml -->
<servlet>
    <servlet-name>em</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

您还必须的web.xml 配置请求映射到相应的 DispatcherServlet的。例如,每个区域可以具有不同的URL路径。

You must also configure web.xml to map requests to the appropriate DispatcherServlet. For example, each region could have a different URL path.

<servlet-mapping>
    <servlet-name>ap</servlet-name>
    <url-pattern>/ap/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>em</servlet-name>
    <url-pattern>/em/*</url-pattern>
</servlet-mapping>

这篇关于如何DispatcherServlet的工作,如果我们有多个XML配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆