多个应用程序上下文,多个调度程序 servlet? [英] Multiple application context, multiple dispatcher servlets?

查看:23
本文介绍了多个应用程序上下文,多个调度程序 servlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到现在我一直认为一个 web 应用程序只能有一个 dispatcher-servlet 我们在 web.xml

中定义
  • 我这样想对吗?
  • 我可以在一个 Web 应用程序中拥有多个调度程序 servlet 吗?如果是,如何?
  • 在什么情况下我们可能需要它?
  • 整个 Web 应用程序中能否只有一个应用程序上下文?
  • 我们如何定义多个应用程序上下文?
  • dispatcher-servlet 可以存在于非 spring 应用程序中吗?

解决方案

您可以在一个 Web 应用程序中拥有多个调度程序 servlet 吗?

当然,引用官方文档(粗体实际上也有!)

<块引用>

Web 应用程序可以定义任意数量的 DispatcherServlet.每个 servlet 将在自己的命名空间中运行,使用映射、处理程序等加载自己的应用程序上下文.只有 ContextLoaderListener 加载的根应用程序上下文(如果有)才会共享.

<小时><块引用>

怎么样?

只需使用org.springframework.web.servlet.DispatcherServlet 类声明几个名称不同的servlet.还要确保 yourServletName-servlet.xml 文件可用.

<小时><块引用>

在什么情况下我们可能需要这个?

DispatcherServlet 非常灵活.不仅 Spring MVC 使用它,Spring WS 也使用它,Spring 支持

<小时><块引用>

另外,在整个 Web 应用程序中可以只有一个应用程序上下文吗?

已经在引用的文档中给出了答案:每个 DispatcherServlet 一个应用程序上下文 + 一个主要的 Web 应用程序上下文.

<小时><块引用>

我们如何定义多个应用程序上下文?

见上,创建多个DispatcherServlet即可.

<小时><块引用>

调度程序 servlet 可以存在于非 Spring 应用程序中吗?

DispatcherServlet 本身就是一个 Spring 上下文(Spring 应用程序),因此:不是.一方面,DispatcherServlet 可以在没有父(主)应用程序上下文的应用程序中声明,因此:是.

Until now I used to think that a web-application can have only one dispatcher-servlet which we define in web.xml

  • Am I right in thinking so?
  • Can i have multiple dispatcher servlets in a single web application? If yes, How?
  • What is a situation we might need this in?
  • Can there only be a single application context in the entire web application?
  • How can we define multiple application contexts?
  • Can a dispatcher-servlet exist in a non-spring application?

解决方案

Can you have multiple dispatcher servlets in a single web application ?

Of course, quoting the official documentation (bold is actually there as well!)

A web application can define any number of DispatcherServlets. Each servlet will operate in its own namespace, loading its own application context with mappings, handlers, etc. Only the root application context as loaded by ContextLoaderListener, if any, will be shared.


How?

Just declare several servlets with different names but using org.springframework.web.servlet.DispatcherServlet class. Also make sure yourServletName-servlet.xml file is available.


What is a situation we might need this in ?

DispatcherServlet is very flexible. Not only Spring MVC uses it, but also Spring WS, Spring support for , etc.


Also, can there only be a single application context in the entire web application ?

Answered already, also in the quoted documentation: one application context per DispatcherServlet + one main web application context.


How can we define multiple application contexts ?

See above, just create multiple DispatcherServlets.


Can a dispatcher servlet exist in a non-spring application ?

DispatcherServlet is a Spring context (Spring application) on its own, thus: no. On the hand DispatcherServlet can be declared in an application not having parent (main) application context, thus: yes.

这篇关于多个应用程序上下文,多个调度程序 servlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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