如何DispatcherServlet的工作,如果我们有多个XML配置文件? [英] How does DispatcherServlet work if we have multiple XML Configuration file?
问题描述
问题
的如何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 EM
and 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屋!