我在Jboss 4.2.3.GA上運行Stripes Web應用程序,並試圖在啓動JBoss時調用方法。我創建了一個ServletContextListener來,像這樣:爲什麼contextInitialized()被多次調用?
public class TimerContextListener implements ServletContextListener {
@Inject
private TimerManager timerManager;
public void contextInitialized(ServletContextEvent servletcontextevent) {
((Injector) servletcontextevent.getServletContext().getAttribute(GuiceServletContextListener.KEY)).injectMembers(this);
timerManager.stopAllTimers();
timerManager.startTimer();
}
public void contextDestroyed(ServletContextEvent servletcontextevent) {
}
}
和我說在web.xml中的條目像這樣:
<listener>
<listener-class>com.lawless.web.servletContextListeners.TimerContextListener</listener-class>
</listener>
但contextInitialized()獲取調用3次,當我開始我的服務器。任何想法可能是什麼問題?謝謝。
將基本'System.out.println'你'contextInitialized'的頂部,以確保你所看到的,你認爲你所看到的。順便說一下,我已經看到了這樣一個問題:將Tomcat連接到NetBeans以供開發時使用的已知錯誤會導致[Tomcat雙啓動Web應用程序](https://stackoverflow.com/q/16702011/642706) 。 – 2017-06-01 22:11:52