I have a @WebListener annotated class in a war that was being called in jetty 9.2.2 but when I switch to 9.2.3 its not being run.
I’ve created a minimal demo project at:
https://github.com/jalbrecht-uptime/jetty-9.2.3-weblistener-bug
that shows what I’m seeing. To reproduce, just take the war and drop it into a jetty-distribution webapps dir and watch the logs.
Do I have to do something extra in 9.2.3?
The demo just creates a war file that has one class in it that is annotated with @WebListener. It just logs when contextInitialized or contextDestroyed are called.
I’ve also checked in the log output for 9.2.2 and 9.2.3 to show the difference. I’ve included some of the files from the demo below for reference.
Jon
package org.eclipse.jetty.jalbrecht;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class ApplicationContextListener implements ServletContextListener {
private static final Logger LOG = Log.getLogger(ApplicationContextListener.class);
@Override public void contextInitialized(ServletContextEvent sce) {
LOG.info("contextInitialized called");
}
@Override public void contextDestroyed(ServletContextEvent sce) {
LOG.info("contextDestroyed called");
}
9.2.2 output:
2014-09-10 11:53:14.744:INFO::main: Logging initialized @577ms
2014-09-10 11:53:15.018:INFO:oejs.Server:main: jetty-9.2.2.v20140723
2014-09-10 11:53:15.065:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/D:/jetty/jetty-distribution-9.2.2.v20140723/webapps/] at interval 1
2014-09-10 11:53:15.068:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/C:/Users/jalbrecht/AppData/Local/Temp/context3352913827613025120deploy/] at interval 1
2014-09-10 11:53:15.092:INFO:oejs.ServerConnector:main: Started ServerConnector@11c757a1{HTTP/1.1}{0.0.0.0:9993}
2014-09-10 11:53:15.093:INFO:oejs.Server:main: Started @932ms
2014-09-10 11:53:17.977:INFO:oejj.ApplicationContextListener:Scanner-1: contextInitialized called
9.2.3 output:
2014-09-10 11:31:13.399:INFO::main: Logging initialized @607ms
2014-09-10 11:31:13.669:INFO:oejs.Server:main: jetty-9.2.3.v20140905
2014-09-10 11:31:13.712:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/D:/jetty/jetty-distribution-9.2.3.v20140905/webapps/] at interval 1
2014-09-10 11:31:17.364:INFO:oejsh.ContextHandler:main: Started
o.e.j.w.WebAppContext@4717fc2e{/uptime-eventstream,file:/C:/Users/jalbrecht/AppData/Local/Temp/jetty-0.0.0.0-9993-uptime-eventstream.war-_uptime-eventstream-any-3031020156445517990.dir/webapp/,AVAILABLE}{D:\jetty\jetty-distribution-9.2.3.v20140905\webapps\uptime-eventstream.war}
2014-09-10 11:31:17.422:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/C:/Users/jalbrecht/AppData/Local/Temp/context869239105066338134deploy/] at interval 1
2014-09-10 11:31:17.445:INFO:oejs.ServerConnector:main: Started ServerConnector@7b687e27{HTTP/1.1}{0.0.0.0:9993}
2014-09-10 11:31:17.446:INFO:oejs.Server:main: Started @4660ms
2014-09-10 11:31:19.718:INFO:oejsh.ContextHandler:Scanner-1: Started
o.e.j.w.WebAppContext@6ffe8d15{/JettyWebListenerBug,file:/C:/ws/jetty-weblistener-bug/target/JettyWebListenerBug/,AVAILABLE}{C:\ws\jetty-weblistener-bug\target\JettyWebListenerBug.war}