WELD-001300 when trying to lookup BeanManager by J

2019-05-18 13:14发布

问题:

I configured Jetty 9.2.5 + Weld 2.2.7 (currently the latest versions) as described by the Weld documentation.

Everything works fine, except the lookup of the BeanManager by JNDI. Lookup of other JNDI entries just work as expected. I got the error (note this is not a javax.naming.NameNotFoundException)

javax.naming.NamingException: WELD-001300: Unable to locate BeanManager

The code I use:

BeanManager beanManager = null;
try {
    final Context ctx = new InitialContext();
    try {
        // JNDI name defined by spec
        beanManager = (BeanManager) ctx.lookup("java:comp/BeanManager");
    } catch (NameNotFoundException nf1) {
        try {
            // JNDI name used by Tomcat and Jetty
            beanManager = (BeanManager) ctx.lookup("java:comp/env/BeanManager");
        } catch (NameNotFoundException nf2) {
        }
    }
} catch (NamingException ex) {
    System.err.println(ex);
}
return beanManager;

Complete test code can be found at https://github.com/rmuller/java8-examples/tree/master/jetty-maven-cdi

回答1:

This has similar symptoms to a problem I ran into with Tomcat 7/8 and Weld 2.2.6. In my case, it was related to a bug in WELD, which was fixed in 2.2.7. So it shouldn't have been affecting the original poster's setup.

https://issues.jboss.org/browse/WELD-1776



标签: Jetty cdi weld