在項目中設置監聽器
1. 首先來看看代碼
listener:監聽
這一塊代碼中,我用了兩個listener標籤,設置了兩個監聽器,當項目啓動,監聽器就啓動了
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.supermap.messageService.tool.pushListener.PushListener</listener-class>
</listener>
ContextLoaderListener的作用就是啓動Web容器時,讀取在contextConfigLocation中定義的xml文件,自動裝配ApplicationContext的配置信息,併產生WebApplicationContext對象,然後將這個對象放置在ServletContext的屬性裏,這樣我們只要得到Servlet就可以得到WebApplicationContext對象,並利用這個對象訪問spring容器管理的bean。
簡單來說,ContextLoaderListener這段配置爲項目提供了spring支持,初始化了Ioc容器。
PushListener是我自己寫的監聽類,作用是進行輪詢