2016-04-28 37 views
1

我有一个webapp,我从另一个使用spring的团队继承而来。我一直在试图调试一些奇怪的行为,并想“关闭”任何spring servlet/filters/context-listeners。即使web.xml不包含它,Spring的ContextLoaderListener如何运行?

所以我莫名其妙后干净的去除在web.xml是这个样子...项

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/applicationContext.xml 
    </param-value> 
</context-param> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<listener> 
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 
</listener> 

然而/构建和我们的应用程序我打org.springframework.web.context的运行。方法contextInitialized上的ContextLoaderListener。

所以我的问题是如果我的web.xml不再声明ContextLoadListener作为侦听器来运行它/为什么它正在运行?我看,Spring 3.2.3-RELEASE的源代码似乎没有Servlet 3.0 Annotation @WebServletContextListener。

那么为什么/如何运行这个Context Listener?

enter image description here

+0

你的类路径中是否有任何'WebApplicationInitializer'类? –

+0

检查调度程序servlet是否正在加载任何配置。 – 11thdimension

+0

是org.glassfish.jersey.server.spring.SpringWebApplicationInitializer。其实两个版本是2.5.1,另一个是2.22.1。 – benstpierre

回答

2

的Servlet 3.0引入ServletContainerInitializer

接口,它允许一个库/运行时被通知的网络 应用程序的启动阶段,以及执行小服务程序,过滤器,和听众的任何所需的编程 登记回应它。

如果你的classpath上有spring-web jar,它会隐式注册它自己的这个接口的实现,SpringServletContainerInitializer。这反过来在类路径上扫描WebApplicationInitializer的实现。

你显然有SpringWebApplicationInitializer

[...]通过增加一个弹簧 ContextLoaderListenerServletContext初始化Spring上下文。

您看到的ContextLoaderListener很可能来自于此。