[weld-dev] registering the Weld Servlet listener in a web.xml fragment or TLD

Dan Allen dan.j.allen at gmail.com
Thu Oct 7 13:40:13 EDT 2010


Instead of making the developer add the Weld Servle listener in their
web.xml when using weld-servlet, might we consider registering it for them
automatically but including it in a web.xml fragment or TLD that's bundled
in weld-servlet.jar? The benefit of using the TLD is that it would work in
pre-Servlet 3.0 environments.

META-INF/web-fragment.xml
<web-fragment xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"
    version="3.0">
   <listener>

 <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
   </listener>
</web-fragment>

META-INF/weld.tld
<taglib xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
       http://java.sun.com/xml/ns/javaee
       http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
    <description>
       An empty tag library that registers a listener to bootstrap Weld in a
Servlet container.
    </description>
    <tlib-version>1.0</tlib-version>
    <short-name>w</short-name>
    <uri>http://jboss.org/weld</uri>

    <!--
       This ServletContextListener initializes the runtime environment of
the CDI
       Reference Implementation (Weld) when a web application including it
is
       initialized by the container.
    -->
    <listener>

<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
    </listener>
</taglib>

Btw, we are already including other automatic configurations, such as a JSF
phase listener and view handler (META-INF/faces-config.xml).

Worthy of a JIRA?

-Dan

-- 
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

http://mojavelinux.com
http://mojavelinux.com/seaminaction
http://www.google.com/profiles/dan.j.allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/weld-dev/attachments/20101007/ff62683c/attachment.html 


More information about the weld-dev mailing list