I create Grizzly WebappContext this way:
WebappContext webContext = new WebappContext("WebappContext", "");
And I have MyInitializer that implements ServletContainerInitializer
. How can I add this initializer to webContext? I tried this way:
webContext.addListener(new MyInitializer());
But MyInitializer.onStartup
method is never called. How to do it?
ServletContainerInitializer
is based on Service Provider Interface (SPI) concept. Implementation of ServletContainerInitializer
interface must be configured in META-INF/services/javax.servlet.ServletContainerInitializer
file.
This jar
contains a listener must be in WEB-INF/lib
of a ServletContainer.
webContext.addListener
will serve your needs but the given listener must be an instance of one or more of the following interfaces:
- javax.servlet.ServletContextAttributeListener
- javax.servlet.ServletRequestListener
- javax.servlet.ServletRequestAttributeListener
- javax.servlet.http.HttpSessionListener
- javax.servlet.http.HttpSessionAttributeListener