I want to test my ServletContextListener with embeded jetty. It calls contextDestroyed
on server stop but doesnt call contextInitialized
on server start. How can I fix it?
Server server = new Server(PORT);
ServletContextListener myListener = ...;
WebAppContext webapp = new WebAppContext();
webapp.addEventListener(myListener);
webapp.setServer(server);
server.setHandler(webapp);
server.start(); -> doesnt call myListener.contextInitialized()
server.stop(); -> call myListener.contextDestroyed()
I had a similar problem with Jetty 9.3.10
Have you tried setting extended listener types to true?
If it is set to false (default), ServletContextListener implementations will not be considered in org.eclipse.jetty.server.handler.ContextHandler.Context#checkListener
webapp.getServletContext().setExtendedListenerTypes(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With