weld/core — pull request #435 by janbartel (2013-12-13 05:03:41+00:00)
Title: Add ServletContainerInitializer implementation for booting Weld

This is an implementation of a javax.servlet.ServletContainerInitializer (servlet 3 api) that boots up the Weld framework for servlet containers.

The code is copied more or less verbatim from the org.jboss.weld.environment.servlet.Listener (some more refactoring might be a good idea to share the code?)

The purpose is to enable the bootup of the Weld framework work in all servlet containers. The existing Weld Listener conceptually has problems because it is a ServletContextListener that is attempting to modify the environment for Servlets, Filters and other ServletContextListeners. The latter is the problem, as a ServletContextListener modifying the environment for other listeners makes a lot of assumptions about the way containers implement the startup handling of listeners.

By using a ServletContainerInitializer, containers must guarantee that they run before any user code, thus ensuring that the Weld setup completes before anything else.

The other benefit of a ServletContainerInitializer is that the user does not have to add anything to web.xml - the container will discover the ServletContainerInitializer and call it back at the appropriate time.

This came about due to a bug raised on Jetty: https://bugs.eclipse.org/bugs/show_bug.cgi?id=423361

I have tested it against jetty-9.1.1 HEAD with a simple webapp based on https://github.com/KlausBrunner/cditest, with the addition of a web.xml containing only:
<listener>
<listener-class>org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener</listener-class>
</listener>
<listener>
<listener-class>test.ContextListener</listener-class>
</listener>

I'd be happy to get your feedback, and eventually have this ServletContainterInitializer contributed to Weld so that we could document its use with the Jetty project.

thanks
Jan