【问题标题】:ContextLoadListener and DispatcherServletContextLoadListener 和 DispatcherServlet
【发布时间】:2010-07-13 05:58:39
【问题描述】:

是否可以在 web.xml 中同时定义 ContextLoadListener 和 DispatcherServlet 或者它们是互斥的?

【问题讨论】:

    标签: spring web.xml


    【解决方案1】:

    不,它们不是相互排斥的。

    ContextLoaderListener 管理与整个 webapp 关联的 appcontext。 DispatcherServlet 管理与该特定 servlet 关联的上下文。 webapp 上下文是 servlet appcontext 的“父级”,webapp appcontext 中的所有 bean 对 servlet appcontext 中的 bean 都是可见的。

    如果您只有一个 servlet,那么使用ContextLoaderListener 的理由并不多。如果您有多个 servlet,最好将共享 bean 放在 webbapp 上下文中,以便可以重复使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-13
      • 2012-06-14
      • 2016-09-12
      • 1970-01-01
      • 2012-07-05
      • 2017-08-30
      • 1970-01-01
      • 2014-09-22
      相关资源
      最近更新 更多