【问题标题】:difference between ContextLoader and ContextLoaderListenerContextLoader 和 ContextLoaderListener 的区别
【发布时间】:2023-03-03 00:37:01
【问题描述】:

ContextLoader 和 ContextLoaderListener 的区别我不明白区别。我试图在谷歌上搜索,但我无法搜索。请帮我解决这个问题。

【问题讨论】:

  • @SaviNuclear 先尝试更友好

标签: java servlets servletcontextlistener servlet-listeners guice-servlet


【解决方案1】:

执行根应用程序上下文的实际初始化工作。由ContextLoaderListenerContextLoaderServlet 调用。

考虑 web.xml 上下文参数级别的 "contextClass" 参数,如果未找到则回退到默认上下文类 (XmlWebApplicationContext)。使用默认的 ContextLoader,上下文类需要实现 ConfigurableWebApplicationContext。

"contextConfigLocation" 上下文参数传递给上下文实例,将其解析为可能的多个文件路径,这些路径可以用任意数量的逗号和空格分隔,例如"applicationContext1.xmlapplicationContext2.xml"。如果没有明确指定,上下文实现应该使用默认位置(使用 XmlWebApplicationContext: `


注意:如果有多个配置位置,后面的 bean 定义 将覆盖之前加载的文件中定义的文件,至少在 使用 Spring 的默认 ApplicationContext 实现之一。这 可以通过以下方式故意覆盖某些 bean 定义 一个额外的 XML 文件。

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/context/ContextLoader.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-12
    • 2011-11-20
    • 2012-06-14
    • 2016-06-09
    • 1970-01-01
    • 2014-12-15
    • 2011-01-12
    相关资源
    最近更新 更多