加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Spring中的DispatcherServlet和ContextLoaderListener

发布时间:2020-12-15 01:24:03 所属栏目:大数据 来源:网络整理
导读:Spring框架中的DispatcherServlet和ContextLoaderListener有什么区别?当我们使用spring框架时,我们是否需要在web.xml中配置它们? 最佳答案 根WebApplicationContext是在应用程序中共享的Spring Application Context. A DispatcherServlet instance actuall

Spring框架中的DispatcherServlet和ContextLoaderListener有什么区别?当我们使用spring框架时,我们是否需要在web.xml中配置它们?

最佳答案
根WebApplicationContext是在应用程序中共享的Spring Application Context.

A DispatcherServlet instance actually has its own
WebApplicationContext.

可以在应用程序中拥有多个DispatcherServlet实例,每个实例都有自己的WebApplicationContext.

The root WebApplicationContext is shared across
the application,so if you have a root WebApplicationContext and
multiple DispatcherServlets,the DispatcherServlets will share the
root WebApplicationContext.

但是,对于一个简单的Spring MVC应用程序,甚至可以在不需要根WebApplicationContext的情况下使用. DispatcherServlet仍然有自己的WebApplicationContext,但实际上并不需要父根WebApplicationContext.

那么,哪些bean应该放在根Web应用程序上下文中,哪些bean应该放在DispatcherServlet的Web应用程序上下文中?
好吧,服务和DAO等通用bean在根Web应用程序上下文中出现,而DispatcherServlet的Web应用程序上下文中包含更多特定于Web的bean,如控制器.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读