2016-04-28 29 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很可能來自於此。

相關問題