微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring中的DispatcherServlet和ContextLoaderListener

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,如控制器.

原文地址:https://www.jb51.cc/spring/431921.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐